1、画游戏头 2、初始化地图(加载地图所需要的资源) 将整数数组中的数字编程控制台中显示的特殊字符串的这个过程 就是初始化地图 3、画地图
4、玩游戏
游戏规则: 如果玩家A踩到了玩家B 玩家B退6格 踩到了地雷 退6格 踩到了时空隧道 进10格 踩到了幸运轮盘 1交换位置 2 轰炸对方 使对方退6格 踩到了暂停 暂停一回合 踩到了方块 神马都不干
Map[50] if(map[40]==1) { Console.WriteLine("◎"); }
//初始化地图 Map[6]=1 //我用0表示普通,显示给用户就是 □ //....1...幸运轮盘,显示组用户就◎ //....2...地雷,显示给用户就是 ☆ //....3...暂停,显示给用户就是 ▲ //....4...时空隧道,显示组用户就 卐 int[] luckyturn = { 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 };//时空隧道卐 for(int i=0;i<luckyturn.Length;i++) { int n=luckyturn[i]; Map[n]=1; } for(int i=0;i<landMine.Length;i++) { int n=landMine[i]; Map[n]=1; }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace 飞行棋 7 { 8 class Program 9 { 10 11 static int[] Maps = new int[100]; 12 static int[] PlayerPos = new int[2]; 13 static string[] PlayerNames = new string[2]; 14 static bool[] Flags = new bool[2]; 15 16 static void Main(string[] args) 17 { 18 GameShow(); 19 #region 输入玩家姓名 20 Console.WriteLine("请输入玩家A的姓名"); 21 PlayerNames[0] = Console.ReadLine(); 22 while(PlayerNames[0] == "") 23 { 24 Console.WriteLine("玩家姓名不能为空,请重新输入!"); 25 PlayerNames[0] = Console.ReadLine(); 26 } 27 Console.WriteLine("请输入玩家B的姓名"); 28 PlayerNames[1] = Console.ReadLine(); 29 while (PlayerNames[1] == "" || PlayerNames[1] == PlayerNames[0]) 30 { 31 if (PlayerNames[1] == "") 32 { 33 Console.WriteLine("玩家姓名不能为空,请重新输入!"); 34 PlayerNames[1] = Console.ReadLine(); 35 } 36 else 37 { 38 Console.WriteLine("玩家B姓名不能和玩家A姓名一样,请重新输入!"); 39 PlayerNames[1] = Console.ReadLine(); 40 } 41 } 42 #endregion 43 Console.Clear(); 44 GameShow(); 45 Console.WriteLine("{0}的士兵用A表示", PlayerNames[0]); 46 Console.WriteLine("{0}的士兵用B表示", PlayerNames[1]); 47 InitialMap(); 48 DrawMap(); 49 while (PlayerPos[0] < 99 && PlayerPos[1] < 99) 50 { 51 if (Flags[0] == false) 52 { 53 PlayGame(0); 54 } 55 else 56 { 57 Flags[0]=false; 58 } 59 if (PlayerPos[0] >= 99) 60 { 61 Console.WriteLine("玩家{0}无耻的赢了玩家{1}", PlayerNames[0], PlayerNames[1]); 62 break; 63 } 64 if (Flags[1] == false) 65 { 66 PlayGame(1); 67 } 68 else 69 { 70 Flags[1] = false; 71 } 72 if (PlayerPos[1] >= 99) 73 { 74 Console.WriteLine("玩家{0}无耻的赢了玩家{1}", PlayerNames[1], PlayerNames[0]); 75 break; 76 } 77 } 78 Console.ReadKey(); 79 } 80 81 ///82 /// 画游戏头 83 /// 84 public static void GameShow() 85 { 86 Console.ForegroundColor = ConsoleColor.Yellow; 87 Console.WriteLine("************************"); 88 Console.ForegroundColor = ConsoleColor.Green; 89 Console.WriteLine("************************"); 90 Console.ForegroundColor = ConsoleColor.Red; 91 Console.WriteLine("************************"); 92 Console.ForegroundColor = ConsoleColor.Cyan; 93 Console.WriteLine("*******飞行棋游戏*******"); 94 Console.ForegroundColor = ConsoleColor.DarkCyan; 95 Console.WriteLine("************************"); 96 Console.ForegroundColor = ConsoleColor.Blue; 97 Console.WriteLine("************************"); 98 } 99 100 ///101 /// 初始化地图102 /// 103 public static void InitialMap()104 {105 int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎106 for (int i = 0; i < luckyturn.Length; i++)107 {108 Maps[luckyturn[i]] = 1;109 }110 int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆111 for (int i = 0; i < landMine.Length; i++)112 {113 Maps[landMine[i]] = 2;114 }115 int[] pause = { 9, 27, 60, 93};//暂停▲116 for (int i = 0; i < pause.Length; i++)117 {118 Maps[pause[i]] = 3;119 }120 int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐121 for (int i = 0; i < timeTunnel.Length; i++)122 {123 Maps[timeTunnel[i]] = 4;124 }125 }126 127 ///128 /// 画地图129 /// 130 public static void DrawMap()131 {132 Console.WriteLine("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卐");133 #region 第一行134 for (int i = 0; i < 30; i++)135 {136 Console.Write(DrawStringMap(i));137 }138 #endregion139 Console.WriteLine();140 #region 第一列141 for (int i = 30; i < 35; i++)142 {143 for (int j = 0; j < 29; j++)144 {145 Console.Write(" ");146 }147 Console.WriteLine(DrawStringMap(i));148 }149 #endregion150 #region 第二行151 for (int i = 64; i > 34; i--)152 {153 Console.Write(DrawStringMap(i));154 }155 #endregion156 Console.WriteLine();157 #region 第二列158 for (int i = 65; i < 70; i++)159 {160 Console.WriteLine(DrawStringMap(i));161 }162 #endregion163 #region 第三行164 for (int i = 70; i < 100; i++)165 {166 Console.Write(DrawStringMap(i));167 }168 #endregion169 Console.WriteLine();170 }171 172 ///173 /// 从画地图的方法中抽象出来的一个方法174 /// 175 /// 176 ///177 public static string DrawStringMap(int i)178 {179 string str = "";180 if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)181 {182 str = "<>";183 }184 else if (PlayerPos[0] == i)185 {186 str = "A";187 }188 else if (PlayerPos[1] == i)189 {190 str = "B";191 }192 else193 {194 switch (Maps[i])195 {196 case 0:197 Console.ForegroundColor = ConsoleColor.Yellow;198 str = "□";199 break;200 case 1:201 Console.ForegroundColor = ConsoleColor.Green;202 str = "◎";203 break;204 case 2:205 Console.ForegroundColor = ConsoleColor.Red;206 str = "☆";207 break;208 case 3:209 Console.ForegroundColor = ConsoleColor.Blue;210 str = "▲";211 break;212 case 4:213 Console.ForegroundColor = ConsoleColor.DarkCyan;214 str = "卐";215 break;216 }217 }218 return str;219 }220 221 /// 222 /// 玩游戏223 /// 224 public static void PlayGame(int playerNumber)225 {226 Random r = new Random();227 int rNumber = r.Next(1, 7);228 Console.WriteLine("{0}按任意键开始掷骰子", PlayerNames[playerNumber]);229 Console.ReadKey(true);230 Console.WriteLine("{0}掷出了{1}", PlayerNames[playerNumber], rNumber);231 Console.ReadKey(true);232 Console.WriteLine("{0}按任意键开始行动", PlayerNames[playerNumber]);233 Console.ReadKey(true);234 PlayerPos[playerNumber] += rNumber;235 Console.WriteLine("{0}行动完了", PlayerNames[playerNumber]);236 Console.ReadKey(true);237 ChangePos();238 Console.Clear();239 DrawMap();240 if (PlayerPos[playerNumber] == PlayerPos[1-playerNumber])241 {242 PlayerPos[1-playerNumber] -= 6;243 Console.ReadKey(true);244 }245 else246 {247 switch (Maps[PlayerPos[playerNumber]])248 {249 case 0: Console.WriteLine("玩家{0}踩到了方块,安全", PlayerNames[playerNumber]);250 Console.ReadKey(true);251 break;252 case 1: Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", PlayerNames[playerNumber]);253 string input=Console.ReadLine();254 while (true)255 {256 if (input == "1")257 {258 Console.WriteLine("玩家{0}选择跟对方交换位置", PlayerNames[playerNumber]);259 int temp = PlayerPos[playerNumber];260 PlayerPos[playerNumber] = PlayerPos[1-playerNumber];261 PlayerPos[1-playerNumber] = temp;262 Console.WriteLine("交换完成,请按任意键继续游戏");263 Console.ReadKey(true);264 break;265 }266 else if (input == "2")267 {268 Console.WriteLine("玩家{0}选择轰炸对方", PlayerNames[playerNumber]);269 Console.ReadKey(true);270 PlayerPos[1-playerNumber] -= 6;271 Console.WriteLine("玩家{0}遭到玩家{1}轰炸,退6格", PlayerNames[1-playerNumber], PlayerNames[playerNumber]);272 Console.ReadKey(true);273 break;274 }275 else276 {277 Console.WriteLine("无效选择,请重新选择1--交换位置 2--轰炸对方");278 input = Console.ReadLine();279 }280 }281 break;282 case 2: Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);283 Console.ReadKey(true);284 PlayerPos[playerNumber] -= 6;285 break;286 case 3: Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerNames[playerNumber]);287 Flags[playerNumber] = true;288 Console.ReadKey(true);289 break;290 case 4: Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerNames[playerNumber]);291 PlayerPos[playerNumber] += 10;292 Console.ReadKey(true);293 break;294 }295 }296 ChangePos();297 Console.Clear();298 DrawMap();299 300 }301 302 ///303 /// 当玩家坐标发生改变的时候调用304 /// 305 public static void ChangePos()306 {307 if (PlayerPos[0] < 0)308 {309 PlayerPos[0] = 0;310 }311 if (PlayerPos[0] > 99)312 {313 PlayerPos[0] = 99;314 }315 if (PlayerPos[1] < 0)316 {317 PlayerPos[1] = 0;318 }319 if (PlayerPos[1] > 99)320 {321 PlayerPos[1] = 99;322 }323 }324 }325 }