以下是main函数中内容
static void Main(string[] args)
{
ShowUI();
string A = "";
string B = "";
int sz;//存放色子数字
int i = 0;//用于处理色子循环投掷
int select=0;//用于接受用户的选择
int[] rp = new int[2];//用于记录是否踩雷
int[] zb=new int[2];//用于存储A和B的位置
Random c=new Random();
Console.WriteLine("请输入玩家A的姓名。");
A = Console.ReadLine();
while (A == "")
{
Console.WriteLine("输入姓名不能为空,请重新输入");
A = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名。");
B = Console.ReadLine();
while (B == "" || B == A)
{
if (B == "")
Console.WriteLine("输入不能为空,请重新输入");
else
Console.WriteLine("玩家B的姓名不能与A重复,请重新输入");
B = Console.ReadLine();
}
Console.Clear();
ShowUI();
Console.WriteLine("游戏开始........");
Console.WriteLine("{0}的士兵用A表示", A);
Console.WriteLine("{0}的士兵用B表示", B);
Console.WriteLine("图例:幸运轮盘◎ 地雷☆ 暂停▲ 时空隧道※");
int[] Map = new int[100];
//特殊点的下标
int[] luckyturn = { 6, 23, 40, 55, 69, 83, 98 };
int[] landmine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };
int[] pause = {1,4, 9, 27, 60, 93 };
int[] timetunnel = { 20, 25, 45, 63, 72, 88, 90 };
Map = fuzhi(Map, luckyturn, 1);
Map = fuzhi(Map, landmine, 2);
Map = fuzhi(Map, pause, 3);
Map = fuzhi(Map, timetunnel, 4);
huatu(Map, 0, 0);
Console.WriteLine("按任意键开始游戏!");
Console.ReadKey();
do
{
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
if (rp[i % 2] != 0)
{
rp[i % 2]--;//检测上次该玩家是否踩到暂停,使用i--的目的是方便调整暂停回合数
i++;
continue;
}
sz = c.Next(1, 7);
zb[i % 2] = zb[i % 2] + sz;
Console.WriteLine("玩家{0}掷出了{1},按任意键继续",i%2+1,sz);
Console.ReadKey();
//最优先检查该次投掷后该玩家是否获得胜利
if (zb[i % 2] >= 99)
{
i++;
break;
}
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
Console.WriteLine("按任意键继续");
Console.ReadKey();
//其次检查该玩家是否踩到另一位玩家
if(zb[i%2]==zb[(i+1)%2])
{
zb[(i + 1) % 2] = 0;
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
Console.WriteLine("玩家{0}将玩家{1}踩回起点,按任意键继续",i%2+1,(i+1)%2+1);
Console.ReadKey();
}
//最后检查其他特殊事件
//幸运轮盘
if (Map[zb[i % 2]] == 1)
{
Console.WriteLine("玩家{0}幸运轮盘,输入1交换位置,输入2轰炸对方",i%2+1);
do
{
try
{
select = Convert.ToInt32(Console.ReadLine());
}
catch{}
if(select != 1 && select != 2)
Console.WriteLine("输入不合法,请重新输入1或者2");
} while (select != 1 && select != 2);
if (select == 1)
{
zb[i % 2] = zb[i % 2] ^ zb[(i + 1) % 2];
zb[(i + 1) % 2] = zb[i % 2] ^ zb[(i + 1) % 2];
zb[i % 2] = zb[i % 2] ^ zb[(i + 1) % 2];
}
else
{
zb[(i + 1) % 2] -= 5;
if (zb[(i + 1) % 2] < 0)
zb[(i + 1) % 2] = 0;
}
select = 0;
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
Console.WriteLine("按任意键继续");
Console.ReadKey();
}
//地雷
if (Map[zb[i % 2]] == 2)
{
zb[i % 2] -= 5;
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
Console.WriteLine("玩家{0}踩到地雷,退5格", i % 2 + 1);
Console.WriteLine("按任意键继续");
Console.ReadKey();
}
//暂停
if (Map[zb[i % 2]] == 3)
{
Console.WriteLine("玩家{0}悲剧了,暂停一次",i%2+1);
rp[i % 2] = 1;//这里是数字可以用来设置暂停次数
Console.WriteLine("按任意键继续");
Console.ReadKey();
}
//时空隧道
if (Map[zb[i % 2]] == 4)
{
zb[i % 2] += 10;
Console.Clear();
chu();
huatu(Map, zb[0], zb[1]);
Console.WriteLine("玩家{0}happy了,进入时空隧道,前进10格",i%2+1);
Console.WriteLine("按任意键继续");
Console.ReadKey();
}
i++;
} while (zb[0] < 99 && zb[1] < 99);
//显示胜利玩家,注意有玩家获胜以后i会加一,所以(i+1)%2代表获胜玩家的下标,再+1代表获胜玩家
Console.WriteLine("玩家{0}取得胜利",(i+1)%2+1);
Console.ReadKey();
} |