1、打印游戏头

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ChuangzhiConsel
{class Program{static void Main(string[] args){GameShow();Console.ReadKey();}public static void GameShow(){Console.ForegroundColor = ConsoleColor.DarkRed;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.DarkGreen;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.White;Console.WriteLine("*********飞行棋*********");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Magenta;Console.WriteLine("************************");}}
}

2、初始化飞行棋地图

/// <summary>/// 初始化地图坐标/// </summary>public static void InitialMap(){int[] luckTurn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎for (int i = 0; i < luckTurn.Length; i++){Map[luckTurn[i]] = 1;}int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷★for (int i = 0; i < landMine.Length; i++){Map[landMine[i]] = 2;}int[] pause = { 9, 27, 60, 93 };//暂停▲for (int i = 0; i < pause.Length; i++){Map[pause[i]] = 3;}int[] timeTunnel = { 20, 23, 63, 72, 88, 90 };//时空隧道◆for (int i = 0; i < timeTunnel.Length; i++){Map[timeTunnel[i]] = 4;}}

/// <summary>/// 画地图/// </summary>public static void DrawMap(){#region #第一个横行for (int i = 0; i < 30; i++){Console.Write(DrawPos(i));}#endregion#region#第一个竖行Console.WriteLine();for (int i = 30; i < 35; i++){for (int j = 0; j < 29; j++){Console.Write("  ");}Console.Write(DrawPos(i));Console.WriteLine();}#endregion#region #第二个横行for (int i = 64; i > 34; i--){Console.Write(DrawPos(i));}#endregion#region #第二个竖行Console.WriteLine();for (int i = 65; i < 70; i++){Console.WriteLine(DrawPos(i));}#endregion#region #最后的横行for (int i = 70; i < Map.Length; i++){Console.Write(DrawPos(i));}#endregion}

3、输入AB玩家信息

#region #输入玩家姓名Console.WriteLine("请输入玩家A的昵称:");PlayerName[0] = Console.ReadLine();while (PlayerName[0] == ""){Console.WriteLine("玩家A的昵称不能为空!!!请重新输入:");PlayerName[0] = Console.ReadLine();}Console.WriteLine("请输入玩家B的昵称:");PlayerName[1] = Console.ReadLine();while (PlayerName[1] == ""||PlayerName[1]==PlayerName[0]){if (PlayerName[0] == PlayerName[1]){Console.WriteLine("B玩家不能与A玩家重名,请重新输入:");PlayerName[1] = Console.ReadLine();}else{Console.WriteLine("B玩家不能为空,请重新输入:");PlayerName[1] = Console.ReadLine();}}#endregion

4、开始玩游戏

 public static void PlayGames(int playerNumber){Random r = new Random();int step = r.Next(1, 7);Console.WriteLine("玩家【{0}】按任意键,掷骰子:", PlayerName[playerNumber]);Console.ReadKey(true);//方法的重载,不显示输入内容Console.WriteLine("【{0}】投掷出了:{1}", PlayerName[playerNumber], step);PlayerPos[playerNumber] += step;Console.ReadKey(true);OutofMap(playerNumber);OutofMap(1 - playerNumber);if (PlayerPos[0] == PlayerPos[1])//踩到对方{Console.WriteLine("【{0}】踩到了【{1}】,玩家【{2}】退六格...", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);PlayerPos[1 - playerNumber] -= 6;Console.ReadKey(true);}else{switch (Map[PlayerPos[playerNumber]])//0 1 2 3 4情况{case 0: Console.WriteLine("踩到了方块。"); Console.ReadKey(true); break;case 1: Console.WriteLine("踩到了幸运轮盘,选择:1、交换位置;2、轰炸,使对方退六格。");#region #case1string input = Console.ReadLine();while (true){if (input == "1"){int temp = PlayerPos[0];PlayerPos[0] = PlayerPos[1];PlayerPos[1] = temp;break;}else if (input == "2"){PlayerPos[1 - playerNumber] -= 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;}else{Console.WriteLine("请重新输入数字!选择:1、交换位置;2、轰炸,使对方退六格。");input = Console.ReadLine();}}break;#endregioncase 2: Console.WriteLine("踩到了地雷,退六格。");Console.ReadKey(true); PlayerPos[playerNumber] -= 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[1 - playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;case 3: Console.WriteLine("踩到了暂停,暂停一回合。");Pause_Falgs[playerNumber] = true;Console.ReadKey(true);break;case 4: Console.WriteLine("踩到了时空隧道,前进6格。"); Console.ReadKey(true); PlayerPos[playerNumber] += 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[1 - playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;}}Console.Clear();OutofMap(playerNumber);OutofMap(1 - playerNumber);DrawMap();}

5、代码下载

点击下载完整代码的地址连接

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ChuangzhiConsel
{class Program{//声明全局地图public static int[] Map = new int[100];//声明全局玩家坐标public static int[] PlayerPos = new int[2];//声明全局玩家名称public static string[] PlayerName = new string[2];//启动哪个玩家标记,默认初始值falsepublic static bool[] Pause_Falgs = new bool[2];static void Main(string[] args){GameShow();#region #输入玩家姓名Console.WriteLine("请输入玩家A的昵称:");PlayerName[0] = Console.ReadLine();while (PlayerName[0] == ""){Console.WriteLine("玩家A的昵称不能为空!!!请重新输入:");PlayerName[0] = Console.ReadLine();}Console.WriteLine("请输入玩家B的昵称:");PlayerName[1] = Console.ReadLine();while (PlayerName[1] == "" || PlayerName[1] == PlayerName[0]){if (PlayerName[0] == PlayerName[1]){Console.WriteLine("B玩家不能与A玩家重名,请重新输入:");PlayerName[1] = Console.ReadLine();}else{Console.WriteLine("B玩家不能为空,请重新输入:");PlayerName[1] = Console.ReadLine();}}#endregionConsole.Clear();GameShow();Console.WriteLine("{0}的玩家用A表示,{1}的玩家用B表示。", PlayerName[0], PlayerName[1]);InitialMap();DrawMap();#region #游戏开始while (PlayerPos[0] < (Map.Length - 1) && PlayerPos[1] < (Map.Length - 1)){if (Pause_Falgs[0] == false){PlayGames(0);}else{Pause_Falgs[0] = false;}if (PlayerPos[0] >= 99){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("恭喜玩家【{0}】赢得了比赛!!!", PlayerName[0]);Console.ReadKey(true);break;}if (Pause_Falgs[1] == false){PlayGames(1);}else{Pause_Falgs[1] = false;}if (PlayerPos[1] >= 99){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("恭喜玩家【{0}】赢得了比赛!!!", PlayerName[1]);Console.ReadKey(true);break;}}#endregionWin();Console.ReadKey();}/// <summary>/// 画游戏头/// </summary>public static void GameShow(){Console.ForegroundColor = ConsoleColor.DarkRed;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.DarkGreen;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.White;Console.WriteLine("*********飞行棋*********");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("************************");Console.ForegroundColor = ConsoleColor.Magenta;Console.WriteLine("************************");}/// <summary>/// 初始化地图坐标/// </summary>public static void InitialMap(){int[] luckTurn = { 4, 23, 40, 55, 68, 83 };//幸运轮盘◎for (int i = 0; i < luckTurn.Length; i++){Map[luckTurn[i]] = 1;}int[] landMine = { 2, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷★for (int i = 0; i < landMine.Length; i++){Map[landMine[i]] = 2;}int[] pause = {7, 9, 27, 35,42,60, 93 };//暂停▲for (int i = 0; i < pause.Length; i++){Map[pause[i]] = 3;}int[] timeTunnel = { 20, 23, 63, 72, 88, 90 };//时空隧道◆for (int i = 0; i < timeTunnel.Length; i++){Map[timeTunnel[i]] = 4;}}/// <summary>/// 画地图/// </summary>public static void DrawMap(){Console.ForegroundColor = ConsoleColor.Gray; Console.Write("图例:");Console.ForegroundColor = ConsoleColor.White; Console.Write("正常:□ ");Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("幸运轮盘:◎ ");Console.ForegroundColor = ConsoleColor.Red; Console.Write("地雷:★ ");Console.ForegroundColor = ConsoleColor.Blue; Console.Write("暂停:▲ ");Console.ForegroundColor = ConsoleColor.Green; Console.Write("时空隧道:◆");Console.WriteLine();#region #第一个横行for (int i = 0; i < 30; i++){Console.Write(DrawPos(i));}#endregion#region#第一个竖行Console.WriteLine();for (int i = 30; i < 35; i++){for (int j = 0; j < 29; j++){Console.Write("  ");}Console.Write(DrawPos(i));Console.WriteLine();}#endregion#region #第二个横行for (int i = 64; i > 34; i--){Console.Write(DrawPos(i));}#endregion#region #第二个竖行Console.WriteLine();for (int i = 65; i < 70; i++){Console.WriteLine(DrawPos(i));}#endregion#region #最后的横行for (int i = 70; i < Map.Length; i++){Console.Write(DrawPos(i));}Console.WriteLine();#endregion}/// <summary>/// 判断画坐标/// </summary>/// <param name="i"></param>public static string DrawPos(int i){string str = "";#region//AB坐标相同时,且在地图范围内if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i){Console.ForegroundColor = ConsoleColor.Magenta;str = ">>";}else if (PlayerPos[0] == i){Console.ForegroundColor = ConsoleColor.Magenta;str = "A";//1全角占用一个,2半角占用一个,全角"shift+空格"如AA}else if (PlayerPos[1] == i){Console.ForegroundColor = ConsoleColor.Magenta;str = "B";//1全角占用一个,2半角占用一个,全角"shift+空格"如BB}else{switch (Map[i]){case 0: Console.ForegroundColor = ConsoleColor.White; str = "□"; break;case 1: Console.ForegroundColor = ConsoleColor.Yellow; str = "◎"; break;case 2: Console.ForegroundColor = ConsoleColor.Red; str = "★"; break;case 3: Console.ForegroundColor = ConsoleColor.Blue; str = "▲"; break;case 4: Console.ForegroundColor = ConsoleColor.Green; str = "◆"; break;}}return str;#endregion}/// <summary>/// 相互玩游戏/// </summary>public static void PlayGames(int playerNumber){Random r = new Random();int step = r.Next(1, 7);Console.WriteLine("玩家【{0}】按任意键,掷骰子:", PlayerName[playerNumber]);Console.ReadKey(true);//方法的重载,不显示输入内容Console.WriteLine("【{0}】投掷出了:{1}", PlayerName[playerNumber], step);PlayerPos[playerNumber] += step;Console.ReadKey(true);OutofMap(playerNumber);OutofMap(1 - playerNumber);if (PlayerPos[0] == PlayerPos[1])//踩到对方{Console.WriteLine("【{0}】踩到了【{1}】,玩家【{2}】退六格...", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);PlayerPos[1 - playerNumber] -= 6;Console.ReadKey(true);}else{switch (Map[PlayerPos[playerNumber]])//0 1 2 3 4情况{case 0: Console.WriteLine("踩到了方块。"); Console.ReadKey(true); break;case 1: Console.WriteLine("踩到了幸运轮盘,选择:1、交换位置;2、轰炸,使对方退六格。");#region #case1string input = Console.ReadLine();while (true){if (input == "1"){int temp = PlayerPos[0];PlayerPos[0] = PlayerPos[1];PlayerPos[1] = temp;break;}else if (input == "2"){PlayerPos[1 - playerNumber] -= 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;}else{Console.WriteLine("请重新输入数字!选择:1、交换位置;2、轰炸,使对方退六格。");input = Console.ReadLine();}}break;#endregioncase 2: Console.WriteLine("踩到了地雷,退六格。");Console.ReadKey(true); PlayerPos[playerNumber] -= 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[1 - playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;case 3: Console.WriteLine("踩到了暂停,暂停一回合。");Pause_Falgs[playerNumber] = true;Console.ReadKey(true);break;case 4: Console.WriteLine("踩到了时空隧道,前进6格。"); Console.ReadKey(true); PlayerPos[playerNumber] += 6;if (PlayerPos[0] == PlayerPos[1]) //可能踩到对方{PlayerPos[1 - playerNumber] -= 6;Console.WriteLine("踩到对方,对方退六格...");Console.ReadKey(true);}break;}}Console.Clear();OutofMap(playerNumber);OutofMap(1 - playerNumber);DrawMap();}/// <summary>/// 如果超出地图界限,重置坐标/// </summary>/// <param name="playerNumber"></param>public static void OutofMap(int playerNumber){if (PlayerPos[playerNumber] < 0){PlayerPos[playerNumber] = 0;}else if (PlayerPos[playerNumber] >= 99){PlayerPos[playerNumber] = 99;}}/// <summary>/// 胜利标记/// </summary>public static void Win(){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();}}
}

C#基础(10)——飞行棋游戏相关推荐

  1. C#飞行棋游戏源码WinForm版本详细教程

    C#做的飞行棋游戏(WinForm)版本 逻辑不是很难,很好理解,适合新手练手 先看一下游戏规则 两个人轮流掷骰子红人和绿人(必须自定义名称否则无法进行游戏) 投掷出2,4,6点出门,投掷出6点可以在 ...

  2. Python飞行棋游戏源代码,基于socket网络通信的小游戏,可设置多个游戏房间及参与飞行棋游戏的玩家

    直接运行ludoServer.py即可,然后用浏览器打开http://127.0.0.1:4399/,完成房间创建.房间设置及玩家设备即可开始游戏 完整程序代码下载地址:Python飞行棋游戏源代码 ...

  3. C#基础知识---飞行棋小游戏

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 飞行棋游戏代码(C#)

    220224飞行器v1.0 using System;namespace AeroplaneChess {class Program{//地图static int[] Maps = new int[1 ...

  5. c#飞行棋游戏(控制台)

    需求分析 1.制作游戏头部:游戏头部介绍 2.绘制地图 使用一维数组装整个地图的路线 如果这个位置是0,绘制普通格子□ 如果这个位置是1,绘制幸运轮盘◎ 如果这个位置是2,绘制地雷★ 如果这个位置是3 ...

  6. C#学习编写的飞行棋游戏

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. C#学习第六天 基础语法练习游戏--飞行棋

    前几天学习的实践:游戏---飞行棋 步骤: 1.画游戏头 2.初始化地图(加载地图所需要的资源) 将整个数组中的数字变成控制台中显示的特殊字符串的过程,就是初始化地图 int[100]代表100个符号 ...

  8. 【全栈计划 —— 编程语言之C#】 C# 实现双人飞行棋小游戏

    文章目录 前言 项目结构流程图 项目实现 一.游戏开始界面 二.初始化游戏地图 三.绘制飞行棋地图 四.玩游戏具体逻辑 ① 创建两个玩家角色 ② 具体走到每个关卡触发的结果 ③ 判断胜利 ④ 回首调优 ...

  9. 【C#】制作简单的飞行棋小游戏

    飞行棋双人小游戏 目标:实现飞行棋游戏基础功能 玩家在地图触发道具: 获得道具,可以进行一次选择 1–交换位置 2–让对方退随机格子 踩到炸弹,让对方暂停一回合 乘上了飞机,前进10格 进入隧道,将随 ...

最新文章

  1. SAP JAM的自定义widget编辑功能
  2. 轻松掌握使用 SQL Server 浏览器,解决SQL Server 2005跨网段不能连接问题
  3. 解决iPhone网络软件在睡眠情况断线问题
  4. Android Studio使用说明
  5. matlab生成HEX文件-任意信号 大于64K长度
  6. 【SpringMVC框架】非注解的处理器映射器和适配器
  7. MyEclipse服务器远程调试
  8. 121道分布式面试题和答案
  9. 最炫黑科技还得谷歌!一副眼镜告别学外语,一个地图App在家沉浸式环球游
  10. Odoo12功能增强模块
  11. html5怎么删除站点,dreamweaver里不用的站点怎么删除?
  12. 原生JS拖拽模型(有限制范围的)
  13. 武汉科技大学java题库答案_武汉科技大学 java实验报告 实验二
  14. 开机显示输入最佳预设值_电脑显示输入最佳预设值并重新开机是什么意思
  15. 《长尾理论》读书笔记------”长尾法则--怎样创造一个消费天堂“
  16. Python 爬虫 Selenium 基本使用
  17. 计算机 优质课教案,计算机优质课教案.doc
  18. Matlab使用符号对象求二元函数积分并做图
  19. Python:将Flask测试应用部署到Deta
  20. Ansys Speos | 实现车内氛围灯早期仿真验证

热门文章

  1. 获取CloudFlare上的所有域名的ID (zone_identifier) - by PHP
  2. FPGA实现JPEG-LS图像压缩,有损无损可配置,提供工程源码和技术支持
  3. 小米电视不能访问电脑共享文件的解决方案
  4. android云测如何使用教程,iTestin使用教程-Testin云测.PDF
  5. 刺激战场测试fps软件,腾讯手游助手玩刺激战场怎样设置显示帧数?
  6. jquery-day32
  7. IPv6设备配置选项
  8. matplotlib中关于极坐标轴的控制
  9. VHDL实现USART
  10. 【win10专业版】新建账户激活 Office 2019