else
{
switch (Map[PlayerPos[0]])
{
case 0:
//普通,没有效果
msg = "";
break;
case 1:
//走到了幸运轮盘
Console.Clear();
Console.WriteLine("恭喜你来到了幸运轮盘,请选择运气!");
Console.WriteLine("按任意键进入!");
DrawMap();
Console.WriteLine("恭喜{0}来到了幸运轮盘,请选择运气!", names[PlayerNumber]);
Console.WriteLine("1--交换位置 2--轰炸对方");
int UserInput = ReadInt(1, 2);
if (UserInput == 1)
{//要与对方交换位置
int temp = PlayerPos[0];
PlayerPos[0] = PlayerPos[1];
PlayerPos[1] = temp;
CheckPos();
msg = string.Format("{0}选择与对方交换位置!", names[PlayerNumber]);
}
else//轰炸对方
{
PlayerPos[1 - PlayerNumber] = PlayerPos[1 - PlayerNumber] - 5;
CheckPos();
msg = string.Format("{0}选择轰炸对方,{1}退5格!", names[PlayerNumber], names[1 - PlayerNumber]);
}
break;
case 2:
//踩到地雷
PlayerPos[0] = PlayerPos[0] - 5;
CheckPos();
msg = string.Format("{0}踩到了地雷,退6格!", names[PlayerNumber]);
break;
case 3:
//暂停一次
isStop[0] = true;
msg = string.Format("{0}踩到暂停,暂停一次", names[PlayerNumber]);
break;
case 4:
//时空隧道
PlayerPos[0] = PlayerPos[0] + 10;
CheckPos();
msg = string.Format("{0}进入时空隧道,前进10格!", names[PlayerNumber]);
break;
}
}
Console.Clear();
DrawMap();
if (msg != "")
{
Console.WriteLine(msg);
}
Console.WriteLine("{0}掷出了{1},行动完成!", names[PlayerNumber], step);
Console.WriteLine("*******************玩家A和玩家B的位置如下*******************");
Console.WriteLine("{0}的位置为{1}", names[0], PlayerPos[0]);
Console.WriteLine("{0}的位置为{1}", names[1], PlayerPos[1]);
}
static void Show() //飞行器名称
{
Console.WriteLine("********************************************");
Console.WriteLine("* *");
Console.WriteLine("* 飞 行 棋 *");
Console.WriteLine("* *");
Console.WriteLine("********************************************");
}
static int[] Map = new int[100];
static void NewMap() //绘制新地图 存储字符下标
{
//转盘◎
//地雷※
//暂停▼
//隧道〓
int[] turn = { 5, 15, 25, 35, 75, 48 }; //轮盘
int[] mine = { 6, 16, 32, 24, 64, 52 }; //地雷
int[] stop = { 7, 51, 46, 83, 97, 69 }; //暂停
int[] time = { 9, 65, 95, 75, 84, 91 }; //隧道
for (int i = 0; i < turn.Length; i++)
{
int pos = turn[i];
Map[pos] = 1;
}
for (int i = 0; i < turn.Length; i++)
{
Map[mine[i]] = 2;
}
for (int i = 0; i < stop.Length; i++)
{
Map[stop[i]] = 3;
}
for (int i = 0; i < time.Length; i++)
{
Map[time[i]] = 4;
}
}
static string MapString(int pos) //获得第pos坐标上要绘制的图案
{
string result = "";
if (PlayerPos[0] == pos && PlayerPos[1] == pos) // ||两个都为真才能退出 &&两个中只要有一个为假就退出
{
Console.ForegroundColor = ConsoleColor.Yellow;
result = "<>"; //判断A和B是否都在第i格上
}
else if (PlayerPos[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result = "A"; //判断A在当前格
}
else if (PlayerPos[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result = "B"; //判断B在当前格
}
else
{
switch (Map[pos])
{
case 0:
Console.ForegroundColor = ConsoleColor.White;
result = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
result = "◎";
break;
case 2:
Console.ForegroundColor = ConsoleColor.Green;
result = "※";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
result = "▼";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Magenta;
result = "〓";
break;
}
}
return result;
}
static int[] PlayerPos = { 0, 0 }; //playerPos[0]是玩家A坐标,PlaysPos[1]是玩家B的坐标
static void DrawMap() //绘制地图
{
Console.WriteLine("图例 转盘◎ 地雷※ 暂停▼ 隧道〓");
//绘制第一行,
for (int i = 0; i <= 29; i++)
{
Console.Write(MapString(i));
}
//第一行绘制完毕
Console.WriteLine();
//绘制第一列
for (int i = 30; i <= 34; i++)
{
//绘制29个双空格(半角)
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
//Console.WriteLine(MapString(i));
string str = MapString(i);
Console.WriteLine(str);
}
//绘制第二行
for (int i = 64; i >= 35; i--)
{
Console.Write(MapString(i));
}
Console.WriteLine();
//绘制第二列
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(MapString(i));
}
//绘制第三行
for (int i = 70; i <= 99; i++)
{
Console.Write(MapString(i));
}
Console.WriteLine();
}
static void CheckPos() //确认A.B位置及检查两玩家是否越界
{
for (int i = 0; i <= 1; i++)
{
if (PlayerPos[i] > 99)
{
PlayerPos[i] = 99;
}
if (PlayerPos[i] < 0)
{
PlayerPos[i] = 0;
}
}
}
}
} |