这个是我刚刚自学C#的时候花了几个小时写的,现在发出来给大家看看(其实有很多小bug,我自己发现了,但是懒得改他)如果你们有兴趣可以改改,我很清楚知道哪里有错哦!当然,就是这个垃圾版本大量bug我还是和董德尔(凯哥,我黑你了!!!)完了好多好多把!

代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 飞行棋项目
{
class Program
{
public static int[] mapsSize = new int[100]; //定义一个一维静态int类型数组mapsCodeSize来存储地图
public static string[] playerName = new string[2]; // 定义一个一维静态string类型数组playerName来储存玩家的姓名
public static int[] playerSite = new int[2]; //定义一个一维静态int类型数组playerSite来储存玩家的位置
public static bool[] playerPause = new bool[2]; //定义一个一维静态bool类型数组playerPause来储存玩家是否暂停
public static bool playerFlage = true ; //定义一个静态bool类型字段playerFlage来控制玩游戏的人,若为true玩家A
static void Main(string[] args)
{
PrintGameHead();
#region 输入A、B两玩家的名字
Console.WriteLine("请输入玩家A的名字:");
playerName[0] = Console.ReadLine();
while (playerName[0] == "")
{
Console.WriteLine("玩家A的名字不能为空,请重新输入!");
Console.WriteLine("请输入玩家A的名字:");
playerName[0] = Console.ReadLine();
}//这是判断玩家A名字是否为空while循环的括号
Console.WriteLine("请输入玩家B的名字:");
playerName[1] = Console.ReadLine();
while (playerName[1] == "" || playerName[0] == playerName[1])
{
if (playerName[1] == "")
{
Console.WriteLine("玩家B的名字不能为空,请重新输入!");
Console.WriteLine("请输入玩家B的名字:");
playerName[0] = Console.ReadLine();
}
else
{
Console.WriteLine("玩家B的名字不能与玩家A的名字相同,请重新输入!");
Console.WriteLine("请输入玩家B的名字:");
playerName[0] = Console.ReadLine();
}
}//while
# endregion
Console.Clear();
PrintGameHead();
PrintPlayerDeputation();
GameMapsInitial();
PrintMaps();
while (playerSite[0]!=99&&playerSite[1]!=99)
{
PlayGame();
}
if (playerSite[0]==99)
{
GetWin(playerName[0]);
}
else
{
GetWin(playerName[1]);
}
Console.ReadKey();
}//这是Main()函数的括号
///
/// 向控制台打印游戏头
///
public static void PrintGameHead()
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("**************************");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("**************************");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("**************************");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("******两人飞行棋游戏******");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("**************************");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("*******QQ:370694354*******");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("**************************");
Console.ForegroundColor = ConsoleColor.White;
}
///
/// 初始化游戏地图
///
public static void GameMapsInitial()
{
//我用0表示普通,显示给用户就是 □
//....1...幸运轮盘,显示组用户就◎
//....2...地雷,显示给用户就是 ☆
//....3...暂停,显示给用户就是 ▲
//....4...时空隧道,显示组用户就 卐
int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎
for (int i = 0; i < luckyturn.Length; i++)
{
mapsSize[luckyturn[i]] = 1; //这句代码的含义是将1赋值给mapsSize数组中下标分别为6, 23, 40, 55, 69, 83的元素
}
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆
for (int i = 0; i < landMine.Length; i++)
{
mapsSize[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93 };//暂停▲
for (int i = 0; i < pause.Length; i++)
{
mapsSize[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐
for (int i = 0; i < timeTunnel.Length; i++)
{
mapsSize[timeTunnel[i]] = 4;
}
}
///
/// 向控制台内打印地图
///
public static void PrintMaps()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卐"); //打印图例
//打印第一行地图
for (int i = 0; i < 30; i++)
{
Console.Write(PrintMapsRead(i));
}//for循环的括号
Console.WriteLine();
// 第一竖行
for (int i = 30; i < 35; i++)
{
for (int j = 0; j <= 28; j++)
{
Console.Write(" ");
}
Console.Write(PrintMapsRead(i));
Console.WriteLine();
}
//打印第二行地图
for (int i = 64; i > 34; i--)
{
Console.Write(PrintMapsRead(i));
}//for循环的括号
Console.WriteLine();
//第二竖行
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(PrintMapsRead(i));
}
//打印第三行地图
for (int i = 70; i < 100; i++)
{
Console.Write(PrintMapsRead(i));
}//for循环的括号
Console.WriteLine();
}
///
/// 从PrintMaps()方法出抽象出的子方法
///
/// 循环到的地图坐标
public static string PrintMapsRead(int i)
{
string str = "";
if (playerSite[0] == playerSite[1] && playerSite[0] == i)
{
str = "<>";
}
else if (playerSite[0] == i)
{
str = "A";
}
else if (playerSite[1] == i)
{
str = "B";
}
else
{
switch (mapsSize[i])
{
case 0:
str = "□";
break;
case 1:
str = "◎";
break;
case 2:
str = "☆";
break;
case 3:
str = "▲";
break;
case 4:
str = "卐";
break;
}//switch结构的括号
}
return str;
}
///
/// 向控制台打印两玩家的代号
///
public static void PrintPlayerDeputation()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{0}的士兵用A表示", playerName[0]);
Console.WriteLine("{0}的士兵用B表示", playerName[1]);
Console.ForegroundColor = ConsoleColor.White;
}
///
/// 使玩家永远在地图内,每次改变位置请调用
///
public static void GetInMaps()
{
if (playerSite[0] < 0)
{
playerSite[0] = 0;
}
if (playerSite[0]>99)
{
playerSite[0] = 99;
}
if (playerSite[1] < 0)
{
playerSite[1] = 0;
}
if (playerSite[1]>99)
{
playerSite[1] = 99;
}
}
///
/// 当某一玩家胜利时,向控制台打印胜利信息
///
/// 胜利的玩家名字
public static void GetWin(string n1)
{
if (n1 == playerName[0])
{
Console.WriteLine("{0}无耻的战胜了{1}!",playerName[0],playerName[1]);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" ◆ ");
Console.WriteLine(" ■ ◆ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ◆■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ◆ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ■■■■■■■ ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ●■● ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ● ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ● ■ ");
Console.WriteLine(" ■ ■■ ■■■■■■ ■ ● ●");
Console.ResetColor();
}
else
{
Console.WriteLine("{0}无耻的战胜了{1}!", playerName[1], playerName[0]);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" ◆ ");
Console.WriteLine(" ■ ◆ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ◆■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ◆ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ■■■■■■■ ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ●■● ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ● ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ● ■ ");
Console.WriteLine(" ■ ■■ ■■■■■■ ■ ● ●");
Console.ResetColor();
}
}
public static void PlayGame()
{
if (playerFlage)
{
playerFlage = false;
if (playerPause[0])
{
Console.WriteLine("{0}处于暂停一回合状态,请等待...",playerName[0]);
playerPause[0] = false;
Console.ReadKey(true);
}
else
{
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("{0}按任意键开始掷骰子", playerName[0]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了{1}", playerName[0], rNumber);
playerSite[0] += rNumber;
GetInMaps();
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动", playerName[0]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了", playerName[0]);
Console.ReadKey(true);
//玩家A有可能踩到了玩家B 方块 幸运轮盘 地雷 暂停 时空隧道
if (playerSite[0] == playerSite[1 - 0])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", playerName[0], playerName[1 - 0], playerName[1 - 0]);
playerSite[1 - 0] -= 6;
GetInMaps();
Console.ReadKey(true);
}
else//踩到了关卡
{
//玩家的坐标
switch (mapsSize[playerSite[0]])// 0 1 2 3 4
{
case 0: Console.WriteLine("玩家{0}踩到了方块,安全。", playerName[0]);
Console.ReadKey(true);
break;
case 1: Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", playerName[0]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", playerName[0], playerName[1 - 0]);
Console.ReadKey(true);
int temp = playerSite[0];
playerSite[0] = playerSite[1 - 0];
playerSite[1 - 0] = temp;
Console.WriteLine("交换完成!!!按任意键继续游戏!!!");
Console.ReadKey(true);
break;
}
else if (input == "2")
{
Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", playerName[0], playerName[1 - 0], playerName[1 - 0]);
Console.ReadKey(true);
playerSite[1 - 0] -= 6;
GetInMaps();
Console.WriteLine("玩家{0}退了6格", playerName[1 - 0]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");
input = Console.ReadLine();
}
}
break;
case 2: Console.WriteLine("玩家{0}踩到了地雷,退6格", playerName[0]);
Console.ReadKey(true);
playerSite[0] -= 6;
GetInMaps();
break;
case 3: Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", playerName[0]);
playerPause[0] = true;
Console.ReadKey(true);
break;
case 4: Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", playerName[0]);
playerSite[0] += 10;
GetInMaps();
Console.ReadKey(true);
break;
}//switch
}//else
GetInMaps();//perfect
Console.Clear();
PrintMaps();
}
}//大if
else
{
playerFlage = true;
if (playerPause[1])
{
Console.WriteLine("{0}处于暂停一回合状态,请等待...",playerName[1]);
playerPause[1] = false;
Console.ReadKey(true);
}
else
{
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("{0}按任意键开始掷骰子", playerName[1]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了{1}", playerName[1], rNumber);
playerSite[1] += rNumber;
GetInMaps();
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动", playerName[1]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了", playerName[1]);
Console.ReadKey(true);
//玩家A有可能踩到了玩家B 方块 幸运轮盘 地雷 暂停 时空隧道
if (playerSite[0] == playerSite[1 - 0])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", playerName[1], playerName[1 - 0], playerName[1 - 0]);
playerSite[0] -= 6;
GetInMaps();
Console.ReadKey(true);
}
else//踩到了关卡
{
//玩家的坐标
switch (mapsSize[playerSite[1]])// 0 1 2 3 4
{
case 0: Console.WriteLine("玩家{0}踩到了方块,安全。", playerName[1]);
Console.ReadKey(true);
break;
case 1: Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", playerName[1]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", playerName[1], playerName[1 - 0]);
Console.ReadKey(true);
int temp = playerSite[0];
playerSite[0] = playerSite[1 - 0];
playerSite[1 - 0] = temp;
Console.WriteLine("交换完成!!!按任意键继续游戏!!!");
Console.ReadKey(true);
break;
}
else if (input == "2")
{
Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", playerName[1], playerName[1 - 0], playerName[1 - 0]);
Console.ReadKey(true);
playerSite[0] -= 6;
GetInMaps();
Console.WriteLine("玩家{0}退了6格", playerName[0]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");
input = Console.ReadLine();
}
}
break;
case 2: Console.WriteLine("玩家{0}踩到了地雷,退6格", playerName[1]);
Console.ReadKey(true);
playerSite[1] -= 6;
GetInMaps();
break;
case 3: Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", playerName[1]);
playerPause[1] = true;
Console.ReadKey(true);
break;
case 4: Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", playerName[1]);
playerSite[1] += 10;
GetInMaps();
Console.ReadKey(true);
break;
}//switch
}//else
GetInMaps();//perfect
Console.Clear();
PrintMaps();
}
}//大if
}
}//这是class Program的括号
}//命名空间