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 };//时空隧道
    image.png

    1. using System;
    2. namespace _045_飞行棋
    3. {
    4. class Program
    5. {
    6. #region 静态变量
    7. //用静态变量模拟全局变量
    8. public static int[] Maps = new int[100];
    9. //声明一个静态数组,用来存储玩家A.B的坐标
    10. public static int[] PlayerPos = new int[2];
    11. //存储两个玩家的姓名
    12. public static string[] PlayerNames = new string[2];
    13. public static bool[] Flags = new bool[2];//利用bool值来让玩家暂停一回合
    14. #endregion
    15. static void Main(string[] args)
    16. {
    17. GameShow();
    18. Console.ForegroundColor = ConsoleColor.Yellow;
    19. #region 输入玩家姓名
    20. //输入玩家姓名
    21. Console.WriteLine("请输入玩家A的姓名:");
    22. PlayerNames[0] = Console.ReadLine();
    23. while (PlayerNames[0] == "")
    24. {
    25. Console.WriteLine("玩家A的姓名不能为空!请重新输入:");
    26. PlayerNames[0] = Console.ReadLine();
    27. }
    28. Console.WriteLine("请输入玩家B的姓名:");
    29. PlayerNames[1] = Console.ReadLine();
    30. while (PlayerNames[1] == "" || PlayerNames[1] == PlayerNames[0])
    31. {
    32. if (PlayerNames[1]=="")
    33. {
    34. Console.WriteLine("玩家B的姓名不能为空!请重新输入:");
    35. PlayerNames[1] = Console.ReadLine();
    36. }
    37. else
    38. {
    39. Console.WriteLine("玩家B的姓名不能和玩家A的姓名相同,请重新输入:");
    40. PlayerNames[1] = Console.ReadLine();
    41. }
    42. }
    43. #endregion
    44. //玩家姓名输入过后,清屏
    45. Console.Clear(); //清屏
    46. GameShow();
    47. Console.WriteLine("{0}的昵称用A表示。", PlayerNames[0]);
    48. Console.WriteLine("{0}的昵称用B表示。", PlayerNames[1]);
    49. //在画地图之前,要初始化地图
    50. InitialMap();
    51. DrawMap();
    52. #region 玩游戏
    53. //当玩家A和玩家B没有一个人在终点时,两个玩家不停地玩游戏
    54. while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
    55. {
    56. if (Flags[0] == false)
    57. {
    58. PlayGame(0);
    59. }
    60. else
    61. {
    62. Flags[0] = false;
    63. }
    64. if (PlayerPos[0]>=99)
    65. {
    66. Console.WriteLine("玩家{0}无耻的赢了玩家{1}!", PlayerNames[0], PlayerNames[1]);
    67. break;
    68. }
    69. if (Flags[1] == false)
    70. {
    71. PlayGame(1);
    72. }
    73. else
    74. {
    75. Flags[1] = false;
    76. }
    77. if (PlayerPos[1] >= 99)
    78. {
    79. Console.WriteLine("玩家{0}无耻的赢了玩家{1}!", PlayerNames[1], PlayerNames[0]);
    80. break;
    81. }
    82. }//while
    83. #endregion
    84. Console.ReadKey();
    85. }
    86. /// <summary>
    87. /// 画游戏头
    88. /// </summary>
    89. public static void GameShow()
    90. {
    91. Console.ForegroundColor = ConsoleColor.Yellow;
    92. Console.WriteLine("*********************************");
    93. Console.ForegroundColor = ConsoleColor.Green;
    94. Console.WriteLine("*********************************");
    95. Console.ForegroundColor = ConsoleColor.Red;
    96. Console.WriteLine("*********************************");
    97. Console.ForegroundColor = ConsoleColor.DarkCyan;
    98. Console.WriteLine("***********Wexiao飞行棋**********");
    99. Console.ForegroundColor = ConsoleColor.Blue;
    100. Console.WriteLine("*********************************");
    101. Console.ForegroundColor = ConsoleColor.Magenta;
    102. Console.WriteLine("*********************************");
    103. Console.ForegroundColor = ConsoleColor.Green;
    104. Console.WriteLine("*********************************");
    105. }
    106. /// <summary>
    107. /// 初始化地图
    108. /// </summary>
    109. public static void InitialMap()
    110. {
    111. int[] luckturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘
    112. for (int i = 0; i < luckturn.Length; i++)
    113. {
    114. //int index = luckturn[i];
    115. //Maps[index] = 1;
    116. Maps[luckturn[i]] = 1;
    117. }
    118. int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
    119. for (int i = 0; i < landMine.Length; i++)
    120. {
    121. Maps[landMine[i]] = 2;
    122. }
    123. int[] pause = { 9, 27, 60, 93 };//暂停
    124. for (int i = 0; i < pause.Length; i++)
    125. {
    126. Maps[pause[i]] = 3;
    127. }
    128. int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道
    129. for (int i = 0; i < timeTunnel.Length; i++)
    130. {
    131. Maps[timeTunnel[i]] = 4;
    132. }
    133. }
    134. /// <summary>
    135. /// 画地图
    136. /// </summary>
    137. public static void DrawMap()
    138. {
    139. Console.WriteLine("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卐 ");
    140. #region 第一横行
    141. //第一横行
    142. for (int i = 0; i < 30; i++)
    143. {
    144. //string str = DrawStringMap(i);
    145. //Console.Write(str);
    146. Console.Write(DrawStringMap(i));
    147. }//for
    148. #endregion
    149. //画完第一横行后,应该换行
    150. Console.WriteLine();
    151. #region 第一竖行
    152. //第一竖行
    153. for (int i = 30; i < 35; i++)
    154. {
    155. for (int j = 0; j <= 28; j++)
    156. {
    157. Console.Write(" ");
    158. }
    159. Console.WriteLine(DrawStringMap(i));
    160. }
    161. #endregion
    162. #region 第二横行
    163. //第二横行
    164. for (int i = 64; i >= 35; i--)
    165. {
    166. Console.Write(DrawStringMap(i));
    167. }
    168. #endregion
    169. //画完第二横行后,换行
    170. Console.WriteLine();
    171. #region 第二竖行
    172. //第二竖行
    173. for (int i = 65; i < 70; i++)
    174. {
    175. Console.WriteLine(DrawStringMap(i));
    176. }
    177. #endregion
    178. #region 第三横行
    179. //第三横行
    180. for (int i = 70; i < 100; i++)
    181. {
    182. Console.Write(DrawStringMap(i));
    183. }
    184. #endregion
    185. //画完最后一行后,换行
    186. Console.WriteLine();
    187. }
    188. /// <summary>
    189. /// 画地图单一元素(从画地图中抽象出的一个方法)
    190. /// </summary>
    191. /// <param name="i">地图的单位</param>
    192. /// <returns>返回应该要画的元素</returns>
    193. public static string DrawStringMap(int i)
    194. {
    195. string str = null;
    196. //如果玩家AB坐标相同,并且都在地图上,画一个尖括号
    197. if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
    198. {
    199. //半角
    200. str = "<>";
    201. }
    202. else if (PlayerPos[0] == i)
    203. {
    204. //shift+空格 全角
    205. str = "A";
    206. }
    207. else if (PlayerPos[1] == i)
    208. {
    209. str = "B";
    210. }
    211. else
    212. {
    213. //□◎☆▲卐
    214. switch (Maps[i])
    215. {
    216. case 0:
    217. Console.ForegroundColor = ConsoleColor.White;
    218. str = "□";
    219. break;
    220. case 1:
    221. Console.ForegroundColor = ConsoleColor.Green;
    222. str = "◎";
    223. break;
    224. case 2:
    225. Console.ForegroundColor = ConsoleColor.Red;
    226. str = "☆";
    227. break;
    228. case 3:
    229. Console.ForegroundColor = ConsoleColor.Blue;
    230. str = "▲";
    231. break;
    232. case 4:
    233. Console.ForegroundColor = ConsoleColor.Cyan;
    234. str = "卐";
    235. break;
    236. }//switch
    237. }//else
    238. return str;
    239. }
    240. /// <summary>
    241. /// 玩家开始投掷投掷,玩游戏
    242. /// </summary>
    243. public static void PlayGame(int playerNumber)
    244. {
    245. Random r = new Random();
    246. int rNumber = r.Next(1, 7);
    247. Console.WriteLine("{0}按任意键开始投掷骰子", PlayerNames[playerNumber]);
    248. Console.ReadKey(true);
    249. Console.WriteLine("{0}掷出了{1}", PlayerNames[playerNumber],rNumber);
    250. PlayerPos[playerNumber] += rNumber;
    251. Console.ReadKey(true);
    252. Console.WriteLine("{0}按任意键开始行动", PlayerNames[playerNumber]);
    253. Console.ReadKey(true);
    254. Console.WriteLine("{0}行动完了", PlayerNames[playerNumber]);
    255. Console.ReadKey(true);
    256. //玩家A可能踩到了玩家B,方块,幸运轮盘,炸弹,暂停,时空隧道
    257. if (PlayerPos[playerNumber] == PlayerPos[1- playerNumber])
    258. {
    259. Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);
    260. PlayerPos[1- playerNumber] -= 6;
    261. Console.ReadKey(true);
    262. }
    263. else//踩到了关卡
    264. {
    265. // 玩家的坐标
    266. switch (Maps[PlayerPos[playerNumber]])
    267. {
    268. case 0: Console.WriteLine("玩家{0}踩到了方块,安全", PlayerNames[playerNumber]); break;
    269. case 1:
    270. Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1--与玩家B交换位置 2--轰炸对方", PlayerNames[playerNumber]);
    271. string input = Console.ReadLine();
    272. while (true)
    273. {
    274. if (input == "1")
    275. {
    276. Console.WriteLine("玩家{0}选择与玩家{1}交换位置", PlayerNames[playerNumber], PlayerNames[1- playerNumber]);
    277. int temp = PlayerPos[playerNumber];
    278. PlayerPos[playerNumber] = PlayerPos[1- playerNumber];
    279. PlayerPos[1- playerNumber] = temp;
    280. Console.WriteLine("交换完成!请按任意键继续游戏。");
    281. break;//跳出while循环
    282. }
    283. else if (input == "2")
    284. {
    285. Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);
    286. PlayerPos[1- playerNumber] -= 6;
    287. Console.WriteLine("玩家{0}退了6格", PlayerNames[1- playerNumber]);
    288. break;//跳出while循环
    289. }
    290. else
    291. {
    292. Console.WriteLine("只能输入1或者2, 1--与玩家B交换位置 2--轰炸对方");
    293. input = Console.ReadLine();
    294. }
    295. }
    296. //Console.ReadKey(true);
    297. break;
    298. case 2:
    299. Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);
    300. PlayerPos[playerNumber] -= 6;
    301. break;
    302. case 3:
    303. Flags[playerNumber] = true;
    304. Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayerNames[playerNumber]);
    305. break;
    306. case 4:
    307. Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerNames[playerNumber]);
    308. PlayerPos[playerNumber] += 10;
    309. break;
    310. }//swicth
    311. Console.ReadKey(true);
    312. }//else
    313. ChangePos();
    314. //清屏,重画地图
    315. Console.Clear();
    316. DrawMap();
    317. }
    318. /// <summary>
    319. /// 当玩家坐标位置发生变化是调用
    320. /// </summary>
    321. public static void ChangePos()
    322. {
    323. if (PlayerPos[0] < 0)
    324. {
    325. PlayerPos[0] = 0;
    326. }
    327. if (PlayerPos[0] >= 99)
    328. {
    329. PlayerPos[0] = 99;
    330. }
    331. if (PlayerPos[1] < 0)
    332. {
    333. PlayerPos[1] = 0;
    334. }
    335. if (PlayerPos[1] >= 99)
    336. {
    337. PlayerPos[1] = 99;
    338. }
    339. }
    340. }
    341. }