using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static string[] name = new string[2]; //name[0]玩家A的名字,name[1]玩家B的名字
static bool bname0 = false; //玩家A取名是否OK
static bool bname1 = false; //玩家B取名是否OK
static int[] diTu = new int[100]; //表示100个地图的位置
static int[] lunPan = { 6, 23, 40, 55, 69, 83 };//幸运轮盘
static int[] diLei = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
static int[] zanTing = { 9, 27, 60, 93 };//暂停
static int[] suiDao = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道
static int[] pos = new int[2]; //存玩家A和玩家B的坐标
static int dianSu = 0; //玩家当前掷出的骰子数
static bool[] bZhiTouZi = new bool[2]; //掷骰子标志
static bool bWin = false; //胜利标志
static bool bExis = false; //退出游戏标志
static void Main(string[] args)
{
Ui();
Console.WriteLine("只能两个人一起玩!!!");
Console.WriteLine("是否开始游戏?输入Y开始游戏,输入别的退出!按Enter键结束");
string input = Console.ReadLine();
if (input != "Y")
{
Console.WriteLine("退出游戏!!!");
bExis = true;
}
else
{
Console.WriteLine("请输入玩家A的名字?按Enter键结束!");
name[0] = Console.ReadLine();
do
{
if (name[0] == "" || name[0] == null)
{
Console.WriteLine("玩家A的名字不能为空,请重新输入!");
name[0] = Console.ReadLine();
}
else
{
Console.WriteLine("取名成功!!!");
Console.WriteLine("玩家A的名字是:" name[0]);
bname0 = true;
}
} while (!bname0);
Console.WriteLine("请输入玩家B的名字?按Enter键结束!");
name[1] = Console.ReadLine();
do
{
if (name[1] == "" || name[1] == null)
{
Console.WriteLine("玩家B的名字不能为空,请重新输入!");
name[1] = Console.ReadLine();
}
else if (name[1] == name[0])
{
Console.WriteLine("用户名已存在,请重新输入!");
name[1] = Console.ReadLine();
}
else
{
Console.WriteLine("取名成功!!!");
Console.WriteLine("玩家B的名字是:" name[1]);
bname1 = true;
}
} while (!bname1);
Console.Clear();
Ui();
Console.WriteLine("玩家A的名字是:" name[0]);
Console.WriteLine("玩家B的名字是:" name[1]);
Console.WriteLine("◎表示幸运轮盘1,☆表示地雷2,▲表示暂停3,卍表示时空隧道4,□表示普通0,");
}
if (!bExis)
{
for (int i = 0; i < lunPan.Length; i )
{
diTu[lunPan[i]] = 1;
}
for (int i = 0; i < diLei.Length; i )
{
diTu[diLei[i]] = 2;
}
for (int i = 0; i < zanTing.Length; i )
{
diTu[zanTing[i]] = 3;
}
for (int i = 0; i < suiDao.Length; i )
{
diTu[suiDao[i]] = 4;
}
if (pos[0] > 99)
{
pos[0] = 99;
}
else if (pos[0] < 0)
{
pos[0] = 0;
}
else if (pos[1] > 99)
{
pos[1] = 99;
}
else if (pos[1] < 0)
{
pos[1] = 0;
}
pos[0] = 0;
pos[0] = 0;
Console.WriteLine("按Enter键开始游戏");
Console.ReadKey();
Console.Clear();
Ui();
Map();
while (!bWin)
{
dianSu = ZhiTouZi(name[0]);
YiDong(name[0], dianSu);
if (bWin)
{
break;
}
dianSu = ZhiTouZi(name[1]);
YiDong(name[1], dianSu);
Console.ReadKey();
Console.Clear();
Ui();
Map();
}
Console.ReadKey();
}
}
/// <summary>
/// 玩家移动后的地图
/// </summary>
/// <param name="name_1">玩家名</param>
/// <param name="dianSu_1">掷出的点数</param>
public static void YiDong(string name_1, int dianSu_1)
{
if (name_1 == name[0])
{
pos[0] = pos[0] dianSu_1;
if (pos[0] > 99)
{
Console.WriteLine("玩家{0}胜利!!!", name_1);
bWin = true;
}
else
{
Map();
for (int i = 0; i < lunPan.Length; i )
{
if (pos[0] == lunPan[i])
{
Console.WriteLine("踩到幸运轮盘,再掷一次");
ZhiTouZi(name_1);
YiDong(name_1, dianSu);
}
}
for (int i = 0; i < diLei.Length; i )
{
if (pos[0] == diLei[i])
{
Console.WriteLine("踩到地雷后退3格");
pos[0] = pos[0] - 3;
Map();
}
}
for (int i = 0; i < zanTing.Length; i )
{
if (pos[0] == zanTing[i])
{
Console.WriteLine("移动到暂停位,休息一下吧");
bZhiTouZi[1] = true;
}
}
for (int i = 0; i < suiDao.Length; i )
{
if (pos[0] == suiDao[i])
{
Console.WriteLine("穿越时空隧道,前进5格");
pos[0] = pos[0] 5;
Map();
}
}
if (bZhiTouZi[0])
{
bZhiTouZi[0] = false;
ZhiTouZi(name_1);
YiDong(name_1, dianSu);
}
}
}
if (name_1 == name[1])
{
pos[1] = pos[1] dianSu_1;
if (pos[1] > 99)
{
Console.WriteLine("玩家{0}胜利!!!", name_1);
bWin = true;
}
else
{
Map();
for (int i = 0; i < lunPan.Length; i )
{
if (pos[1] == lunPan[i])
{
Console.WriteLine("踩到幸运轮盘,再掷一次");
ZhiTouZi(name_1);
YiDong(name_1, dianSu);
}
}
for (int i = 0; i < diLei.Length; i )
{
if (pos[1] == diLei[i])
{
Console.WriteLine("踩到地雷后退3格");
pos[1] = pos[1] - 3;
Map();
}
}
for (int i = 0; i < zanTing.Length; i )
{
if (pos[1] == zanTing[i])
{
Console.WriteLine("移动到暂停位,休息一下吧");
bZhiTouZi[0] = true;
}
}
for (int i = 0; i < suiDao.Length; i )
{
if (pos[0] == suiDao[i])
{
Console.WriteLine("穿越时空隧道,前进5格");
pos[1] = pos[1] 5;
Map();
}
}
if (bZhiTouZi[1])
{
bZhiTouZi[1] = false;
ZhiTouZi(name_1);
YiDong(name_1, dianSu);
}
}
}
}
/// <summary>
/// 掷骰子
/// </summary>
/// <param name="name">玩家名</param>
/// <returns>掷出的骰子值</returns>
public static int ZhiTouZi(string name)
{
Console.WriteLine("玩家{0}开始掷骰子...", name);
Console.WriteLine("请按Enter键掷骰子");
Console.ReadKey();
Console.Clear();
Ui();
Random suiJi = new Random();
dianSu = suiJi.Next(1, 7);
Console.WriteLine("玩家{0}掷出的骰子数是{1}。", name, dianSu);
Console.WriteLine("开始移动!!!");
return dianSu;
}
/// <summary>
/// 绘制初始地图
/// </summary>
public static void Map()
{
for (int i = 0; i < 30; i )
{
if (pos[0] == i && pos[1] == i)
{
Console.Write("<>");
}
else if (pos[0] == i)
{
Console.Write("A");
}
else if (pos[1] == i)
{
Console.Write("B");
}
else
{
switch (diTu[i])
{
case 1:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("☆");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("卍");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.Write("□");
break;
}
}
}
Console.WriteLine();
for (int i = 30; i < 35; i )
{
Console.Write(" ");
if (pos[0] == i && pos[1] == i)
{
Console.Write("<>");
}
else if (pos[0] == i)
{
Console.Write("A");
}
else if (pos[1] == i)
{
Console.Write("B");
}
else
{
switch (diTu[i])
{
case 1:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("☆");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("卍");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.Write("□");
break;
}
}
Console.WriteLine();
}
for (int i = 64; i > 34; i--)
{
if (pos[0] == i && pos[1] == i)
{
Console.Write("<>");
}
else if (pos[0] == i)
{
Console.Write("A");
}
else if (pos[1] == i)
{
Console.Write("B");
}
else
{
switch (diTu[i])
{
case 1:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("☆");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("卍");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.Write("□");
break;
}
}
}
Console.WriteLine();
for (int i = 65; i < 70; i )
{
if (pos[0] == i && pos[1] == i)
{
Console.WriteLine("<>");
}
else if (pos[0] == i)
{
Console.WriteLine("A");
}
else if (pos[1] == i)
{
Console.WriteLine("B");
}
else
{
switch (diTu[i])
{
case 1:
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("☆");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("卍");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("□");
break;
}
}
}
for (int i = 70; i < 100; i )
{
if (pos[0] == i && pos[1] == i)
{
Console.Write("<>");
}
else if (pos[0] == i)
{
Console.Write("A");
}
else if (pos[1] == i)
{
Console.Write("B");
}
else
{
switch (diTu[i])
{
case 1:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("☆");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("卍");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.Write("□");
break;
}
}
}
Console.WriteLine();
}
/// <summary>
/// 飞行棋表头
/// </summary>
public static void Ui()
{
Console.WriteLine("***********************************");
Console.WriteLine("* *");
Console.WriteLine("* 飞行棋 *");
Console.WriteLine("* *");
Console.WriteLine("***********************************");
Console.WriteLine("◎表示幸运轮盘,再掷一次;☆表示地雷,退后3格;▲表示暂停,休息一轮;卍表示时空隧道前进5格,□表示普通.");
}
}
}