using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 飞行棋
{
class Program
{
static int[] Maps = new int[100];
static int[] PlayerPos = new int[2];
static string[] PlayerName = new string[2];
static bool[] Flags = new bool[2];
static void Main(string[] args)
{
GameShow();
#region 输入玩家姓名
Console.WriteLine("请输入玩家A的姓名");
PlayerName[0] = Console.ReadLine();
while (PlayerName[0] == "")
{
Console.WriteLine("玩家A姓名不能为空");
Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名");
PlayerName[1] = Console.ReadLine();
while (PlayerName[1] == "" || PlayerName[0] == PlayerName[1])
{
if (PlayerName[1] == "")
{
Console.WriteLine("玩家B姓名不能为空");
}
else
{
Console.WriteLine("玩家A和玩家B姓名不能相同");
}
Console.ReadLine();
}
#endregion
Console.Clear();
InitailMap();
DrawMap();
#region //玩游戏
while ((PlayerPos[0] < 99) && (PlayerPos[1] < 99))
{
if (Flags[0] == false)
{
PlayGame(0);
}
else
{
Flags[0] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("{0}赢了", PlayerName[0]);
}
if (Flags[1] == false)
{
PlayGame(1);
}
else
{
Flags[1] = false;
}
if (PlayerPos[1] >= 99)
{
Console.WriteLine("{0}赢了", PlayerName[1]);
}
}
#endregion
Console.WriteLine();
Console.ReadKey();
}
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("******************飞行棋******************");
}
public static void InitailMap()
{
int[] luckyTurn = { 5, 13, 17, 33, 6, 23, 40, 55, 69, 83 };
for (int i = 0; i < luckyTurn.Length; i++)
{
Maps[luckyTurn[i]] = 1;
}
int[] landMine = { 38, 50, 64, 80, 94 };
for (int i = 0; i < landMine.Length; i++)
{
Maps[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93 };
for (int i = 0; i < pause.Length; i++)
{
Maps[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };
for (int i = 0; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = 4;
}
}
public static void DrawMap()
{
Console.WriteLine("{0}的士兵用A表示", PlayerName[0]);
Console.WriteLine("{0}的士兵用B表示", PlayerName[1]);
Console.WriteLine("图例:幸运轮盘○,地雷☆,暂停△,时空隧道卍");
#region 第一横行
for (int i = 0; i < 30; i++)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
#region 第一竖行
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
Console.Write(DrawStringMap(i));
Console.WriteLine();
}
#endregion
#region 第二横行
for (int i = 64; i >= 35; i--)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
#region 第二竖行
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 第三横行
for (int i = 70; i <= 99; i++)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
}
public static string DrawStringMap(int i)
{
string str = "";
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
{
str = "<>";
}
else if (PlayerPos[0] == i)
{
str = "A";
}
else if (PlayerPos[1] == i)
{
str = "B";
}
else
switch (Maps[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.Yellow;
str = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
str = "○";
break;
case 2:
Console.ForegroundColor = ConsoleColor.White;
str = "★";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
str = "△";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Green;
str = "卍";
break;
}
return str;
}
public static void PlayGame(int playNumber)
{
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("{0}按任意键开始掷骰子", PlayerName[playNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了{1}点", PlayerName[playNumber], rNumber);
PlayerPos[playNumber] += rNumber;
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动", PlayerName[playNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了", PlayerName[playNumber]);
Console.ReadKey(true);
if (PlayerPos[playNumber] == PlayerPos[1 - playNumber])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退六格", PlayerName[playNumber], PlayerName[1 - playNumber], PlayerName[1 - playNumber]);
PlayerPos[1 - playNumber] -= 6;
}
else
{
switch (Maps[PlayerPos[playNumber]])
{
case 0: Console.WriteLine("{0}踩到了方块,安全", PlayerName[playNumber]);
Console.ReadKey(true);
break;
case 1: Console.WriteLine("{0}踩到了幸运轮盘,选择1交换位置,2轰炸对方", PlayerName[playNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("{0}选择跟{1}交换位置", PlayerName[playNumber], PlayerName[1 - playNumber]);
Console.ReadKey(true);
int temp = PlayerPos[playNumber];
PlayerPos[playNumber] = PlayerPos[1 - playNumber];
PlayerPos[1 - playNumber] = temp;
Console.WriteLine("交换成功");
break;
}
else if (input == "2")
{
Console.WriteLine("{0}选择轰炸{1}", PlayerName[playNumber], PlayerName[1 - playNumber]);
Console.ReadKey(true);
PlayerPos[1 - playNumber] -= 6;
Console.WriteLine("{0}退了六格", PlayerName[1 - playNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或2");
input = Console.ReadLine();
}
}
break;
case 2: Console.WriteLine("{0}踩到了地雷,退六格", PlayerName[playNumber]);
Console.ReadKey(true);
PlayerPos[playNumber] -= 6;
break;
case 3: Console.WriteLine("{0}踩到了暂停,跳过一回合", PlayerName[playNumber]);
Flags[playNumber] = true;
Console.ReadKey(true);
break;
case 4: Console.WriteLine("{0}踩到了时空隧道,前进十格", PlayerName[playNumber]);
Console.ReadKey(true);
PlayerPos[playNumber] += 10;
break;
default:
break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
public static void ChangePos()
{
if (PlayerPos[0] < 0)
{
PlayerPos[0] = 0;
}
if (PlayerPos[0] >= 99)
{
PlayerPos[0] = 99;
}
if (PlayerPos[1] < 0)
{
PlayerPos[1] = 0;
}
if (PlayerPos[1] >= 99)
{
PlayerPos[1] = 99;
}
}
}
}