1、画游戏头
2、初始化地图(加载地图所需要的资源)
将整数数组中的数学编程控制台中豆示的特殊字符串的这个过程就是初始化地图
3、画地图
4、玩游戏
游戏规则:
如果玩家Ai踩到了玩家B玩家B退6格辣到了地雷退6格
辣到了时空道进10格
辣到了幸运轮盘1交换位置2轰炸对方使对方退6格辣到了暂停暂停一回奇
辣到了方块神马都不干
int[] luckturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
int[] pause = { 9, 27, 60, 93 };//暂停
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道
using System;namespace _045_飞行棋{class Program{#region 静态变量//用静态变量模拟全局变量public static int[] Maps = new int[100];//声明一个静态数组,用来存储玩家A.B的坐标public static int[] PlayerPos = new int[2];//存储两个玩家的姓名public static string[] PlayerNames = new string[2];public static bool[] Flags = new bool[2];//利用bool值来让玩家暂停一回合#endregionstatic void Main(string[] args){GameShow();Console.ForegroundColor = ConsoleColor.Yellow;#region 输入玩家姓名//输入玩家姓名Console.WriteLine("请输入玩家A的姓名:");PlayerNames[0] = Console.ReadLine();while (PlayerNames[0] == ""){Console.WriteLine("玩家A的姓名不能为空!请重新输入:");PlayerNames[0] = Console.ReadLine();}Console.WriteLine("请输入玩家B的姓名:");PlayerNames[1] = Console.ReadLine();while (PlayerNames[1] == "" || PlayerNames[1] == PlayerNames[0]){if (PlayerNames[1]==""){Console.WriteLine("玩家B的姓名不能为空!请重新输入:");PlayerNames[1] = Console.ReadLine();}else{Console.WriteLine("玩家B的姓名不能和玩家A的姓名相同,请重新输入:");PlayerNames[1] = Console.ReadLine();}}#endregion//玩家姓名输入过后,清屏Console.Clear(); //清屏GameShow();Console.WriteLine("{0}的昵称用A表示。", PlayerNames[0]);Console.WriteLine("{0}的昵称用B表示。", PlayerNames[1]);//在画地图之前,要初始化地图InitialMap();DrawMap();#region 玩游戏//当玩家A和玩家B没有一个人在终点时,两个玩家不停地玩游戏while (PlayerPos[0] < 99 && PlayerPos[1] < 99){if (Flags[0] == false){PlayGame(0);}else{Flags[0] = false;}if (PlayerPos[0]>=99){Console.WriteLine("玩家{0}无耻的赢了玩家{1}!", PlayerNames[0], PlayerNames[1]);break;}if (Flags[1] == false){PlayGame(1);}else{Flags[1] = false;}if (PlayerPos[1] >= 99){Console.WriteLine("玩家{0}无耻的赢了玩家{1}!", PlayerNames[1], PlayerNames[0]);break;}}//while#endregionConsole.ReadKey();}/// <summary>/// 画游戏头/// </summary>public static void GameShow(){Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("*********************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("*********************************");Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("*********************************");Console.ForegroundColor = ConsoleColor.DarkCyan;Console.WriteLine("***********Wexiao飞行棋**********");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("*********************************");Console.ForegroundColor = ConsoleColor.Magenta;Console.WriteLine("*********************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("*********************************");}/// <summary>/// 初始化地图/// </summary>public static void InitialMap(){int[] luckturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘for (int i = 0; i < luckturn.Length; i++){//int index = luckturn[i];//Maps[index] = 1;Maps[luckturn[i]] = 1;}int[] landMine = { 5, 13, 17, 33, 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;}}/// <summary>/// 画地图/// </summary>public static void DrawMap(){Console.WriteLine("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卐 ");#region 第一横行//第一横行for (int i = 0; i < 30; i++){//string str = DrawStringMap(i);//Console.Write(str);Console.Write(DrawStringMap(i));}//for#endregion//画完第一横行后,应该换行Console.WriteLine();#region 第一竖行//第一竖行for (int i = 30; i < 35; i++){for (int j = 0; j <= 28; j++){Console.Write(" ");}Console.WriteLine(DrawStringMap(i));}#endregion#region 第二横行//第二横行for (int i = 64; i >= 35; i--){Console.Write(DrawStringMap(i));}#endregion//画完第二横行后,换行Console.WriteLine();#region 第二竖行//第二竖行for (int i = 65; i < 70; i++){Console.WriteLine(DrawStringMap(i));}#endregion#region 第三横行//第三横行for (int i = 70; i < 100; i++){Console.Write(DrawStringMap(i));}#endregion//画完最后一行后,换行Console.WriteLine();}/// <summary>/// 画地图单一元素(从画地图中抽象出的一个方法)/// </summary>/// <param name="i">地图的单位</param>/// <returns>返回应该要画的元素</returns>public static string DrawStringMap(int i){string str = null;//如果玩家AB坐标相同,并且都在地图上,画一个尖括号if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i){//半角str = "<>";}else if (PlayerPos[0] == i){//shift+空格 全角str = "A";}else if (PlayerPos[1] == i){str = "B";}else{//□◎☆▲卐switch (Maps[i]){case 0:Console.ForegroundColor = ConsoleColor.White;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Green;str = "◎";break;case 2:Console.ForegroundColor = ConsoleColor.Red;str = "☆";break;case 3:Console.ForegroundColor = ConsoleColor.Blue;str = "▲";break;case 4:Console.ForegroundColor = ConsoleColor.Cyan;str = "卐";break;}//switch}//elsereturn str;}/// <summary>/// 玩家开始投掷投掷,玩游戏/// </summary>public static void PlayGame(int playerNumber){Random r = new Random();int rNumber = r.Next(1, 7);Console.WriteLine("{0}按任意键开始投掷骰子", PlayerNames[playerNumber]);Console.ReadKey(true);Console.WriteLine("{0}掷出了{1}", PlayerNames[playerNumber],rNumber);PlayerPos[playerNumber] += rNumber;Console.ReadKey(true);Console.WriteLine("{0}按任意键开始行动", PlayerNames[playerNumber]);Console.ReadKey(true);Console.WriteLine("{0}行动完了", PlayerNames[playerNumber]);Console.ReadKey(true);//玩家A可能踩到了玩家B,方块,幸运轮盘,炸弹,暂停,时空隧道if (PlayerPos[playerNumber] == PlayerPos[1- playerNumber]){Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);PlayerPos[1- playerNumber] -= 6;Console.ReadKey(true);}else//踩到了关卡{// 玩家的坐标switch (Maps[PlayerPos[playerNumber]]){case 0: Console.WriteLine("玩家{0}踩到了方块,安全", PlayerNames[playerNumber]); break;case 1:Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--与玩家B交换位置 2--轰炸对方", PlayerNames[playerNumber]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("玩家{0}选择与玩家{1}交换位置", PlayerNames[playerNumber], PlayerNames[1- playerNumber]);int temp = PlayerPos[playerNumber];PlayerPos[playerNumber] = PlayerPos[1- playerNumber];PlayerPos[1- playerNumber] = temp;Console.WriteLine("交换完成!请按任意键继续游戏。");break;//跳出while循环}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);PlayerPos[1- playerNumber] -= 6;Console.WriteLine("玩家{0}退了6格", PlayerNames[1- playerNumber]);break;//跳出while循环}else{Console.WriteLine("只能输入1或者2, 1--与玩家B交换位置 2--轰炸对方");input = Console.ReadLine();}}//Console.ReadKey(true);break;case 2:Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);PlayerPos[playerNumber] -= 6;break;case 3:Flags[playerNumber] = true;Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerNames[playerNumber]);break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerNames[playerNumber]);PlayerPos[playerNumber] += 10;break;}//swicthConsole.ReadKey(true);}//elseChangePos();//清屏,重画地图Console.Clear();DrawMap();}/// <summary>/// 当玩家坐标位置发生变化是调用/// </summary>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;}}}}
