直接贴代码

class Program
{static int[] Maps = new int[100];static int[] PlayerPos = new int[2];//玩家A,B的坐标static string[] PlayNames = new string[2];//玩家A,B的姓名static bool[] Flag = new bool[2];//两个玩家的标记static void Main(string[] args){GameShow();#region 输入玩家姓名Console.WriteLine("请输入玩家A的姓名");PlayNames[0] = Console.ReadLine();while (PlayNames[0] == " "){Console.WriteLine("玩家A姓名不能为空,请重新输入");PlayNames[0] = Console.ReadLine();}Console.WriteLine("请输入玩家B的姓名");PlayNames[1] = Console.ReadLine();while(PlayNames[1] == " " || PlayNames[1] == PlayNames[0]){if (PlayNames[1] == " "){Console.WriteLine("玩家B的姓名不能为空,请重新输入");}else{Console.WriteLine("玩家B的姓名不能和玩家A的姓名相同,请重新输入");}PlayNames[1] = Console.ReadLine();}#endregion//此时不需要显示哪个士兵 需要清屏Console.Clear();GameShow();Console.WriteLine("{0}的士兵用A表示", PlayNames[0]);Console.WriteLine("{0}的士兵用B表示", PlayNames[1]);InitailMap();DrawMap();//当玩家A和玩家B没有一个人在终点时 ,两个玩家呀不停的玩游戏while (PlayerPos[0]< 99 && PlayerPos[1]<99){if (Flag[0] == false){PlayGame(0);}else{Flag[0] = false;//如果不写这个 如果第一次暂停 将永远玩不了游戏}if (PlayerPos[0]>=99){Console.WriteLine("玩家{0}赢了玩家{1}",PlayNames[0],PlayNames[1]);}if (Flag[1] == false){PlayGame(1);}else{Flag[1] = false;}if (PlayerPos[1] >= 99){Console.WriteLine("玩家{0}赢了玩家{1}", PlayNames[1], PlayNames[0]);}}Console.ReadKey();}/// <summary>/// 画游戏头/// </summary>public static void GameShow(){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("******************************");Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("******************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("*********dotnet飞行棋*********");Console.ForegroundColor = ConsoleColor.Gray;Console.WriteLine("******************************");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("******************************");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("******************************");}public static void InitailMap(){//0代表方块  1代表幸运轮盘 2代表地雷 3代表暂停  4代表时空隧道 根据这个来画图 int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘for (int i = 0; i < luckyturn.Length; i++){//var index = luckyturn[i];Maps[luckyturn[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]] = 3;}}public static void DrawMap(){Console.WriteLine("图例:幸运轮盘◎    地雷☆     暂停△    时光隧道卍");#region 第一横行for (int i = 0; i < 30; i++){Console.Write(DrawStringMap(i));}Console.WriteLine();#endregion#region 第二竖行for (int i = 30; i < 36; i++){for (int j = 0; j < 29; j++){Console.Write("  ");}Console.Write(DrawStringMap(i));Console.WriteLine();}#endregion#region 第三横行for (int i = 64; i >=35; i--){Console.Write(DrawStringMap(i));}Console.WriteLine();#endregion#region 第四竖行for (int i = 65; i <= 69; i++){Console.WriteLine(DrawStringMap(i));}#endregion#region 第五横行for (int i = 70; i <=99; i++){Console.Write(DrawStringMap(i));}#endregionConsole.WriteLine();//画完地图需要换行 使其光标在下一行}public static string DrawStringMap(int i){string str = "";//先画A B人(用数组存) 位置相同且在地图上//PlayerPos[0]代表A,PlayerPos[1]代表Bif (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i){str= "<>";}else if (PlayerPos[0] == i){str = "A";}else if (PlayerPos[1] == i){str = "B";}else{switch (Maps[i]){case 0:Console.ForegroundColor = ConsoleColor.Red;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Yellow;str = "◎";break;case 2:Console.ForegroundColor = ConsoleColor.Green;str = "☆";break;case 3:Console.ForegroundColor = ConsoleColor.Blue;str = "△";break;case 4:Console.ForegroundColor = ConsoleColor.Cyan;str = "卍";break;default:break;}}return str;}public static void PlayGame(int playNumber){Random random = new Random();int r = random.Next(1,7);Console.WriteLine("玩家{0}按任意键开始掷骰子", PlayNames[playNumber]);Console.ReadKey(true);Console.WriteLine("玩家{0}掷出了{1}", PlayNames[playNumber],r);PlayerPos[playNumber] += r;Console.WriteLine("玩家{0}按任意键开始行动", PlayNames[playNumber]);Console.ReadKey(true);Console.WriteLine("玩家{0}行动完了", PlayNames[playNumber]);Console.ReadKey(true);//游戏规则 玩家A可能踩到玩家B 玩家B退6格 也可能踩到方块 幸运轮盘 地雷 暂停 时空隧道if (PlayerPos[playNumber] == PlayerPos[1- playNumber]){Console.WriteLine("玩家{0}踩到了玩家{1},玩家{1}退6格", PlayNames[playNumber], PlayNames[1- playNumber], PlayNames[1- playNumber]);PlayerPos[1- playNumber] -= 6;Console.ReadKey(true);}else{switch (Maps[PlayerPos[playNumber]]){case 0://方块Console.WriteLine("玩家{0}踩到了方块,安全", PlayNames[playNumber]);break;case 1://幸运轮盘Console.WriteLine("玩家{0}踩到了幸运轮盘 按1交换位置 按2轰炸对象 使对方退6格", PlayNames[playNumber]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("玩家{0}选择与玩家{1}交换位置", PlayNames[playNumber], PlayNames[1- playNumber]);var temp = PlayerPos[playNumber];PlayerPos[playNumber] = PlayerPos[1- playNumber];PlayerPos[1- playNumber] = temp;Console.WriteLine("交换完成,请按任意键继续游戏");Console.ReadKey(true);break;}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1},使玩家{2}退6格", PlayNames[playNumber], PlayNames[1- playNumber], PlayNames[1- playNumber]);PlayerPos[1- playNumber] -= 6;Console.WriteLine("玩家{0}退了6格", PlayNames[1- playNumber]);Console.ReadKey(true);break;}else{Console.WriteLine("玩家{0}重新输入1或2 ,按1交换位置 按2轰炸对象 使对方退6格", PlayNames[playNumber]);input = Console.ReadLine();}}break;case 2:Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayNames[playNumber]);PlayerPos[playNumber] -= 6;Console.ReadKey(true);break;case 3:Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", PlayNames[playNumber]);Flag[playNumber] = true;Console.ReadKey(true);break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayNames[playNumber]);PlayerPos[playNumber] += 10;Console.ReadKey(true);break;}}ChangePos();//判断玩家坐标时Console.Clear();DrawMap();}/// <summary>/// 当玩家坐标改变的时候调用/// </summary>/// <param name="playNumber"></param>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;}}
}

C#基础-飞行棋小游戏相关推荐

  1. C# 实现飞行棋小游戏

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

  2. C# 飞行棋小游戏 (控制台应用)

    目录 C# 控制台飞行棋小游戏 简要介绍 游戏画面 规则说明 游戏代码 `Entry.cs` `Operate.cs` `Map.cs` `Player.cs` 其他问题 C# 控制台飞行棋小游戏 简 ...

  3. C#实现一个控制台飞行棋小游戏(附源码)

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

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

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

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

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

  6. 记录基础学习第二_小项目_飞行棋小游戏

    飞行棋项目: 1.游戏头(要求每一个句子显示不同的颜色 )  //这里用到了Console类中的ForegroundColor属性 取值是枚举类型ConsoleColor中的值             ...

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

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

  8. python飞行棋小游戏

    import random # 地图初始坐标 Maps = [0] *100 # 玩家A和玩家B的初始坐标 PlayerPos = [0]*2 # 存储玩家姓名 playerNames = [&quo ...

  9. C#控制台实现飞行棋小游戏

    游戏标题 static void ShowTitle(){Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("*** ...

最新文章

  1. io vivado 怎么查看ps_ZYNQ 7020学习笔记之PL侧普通信号中断PS的实验
  2. 一些关于Rust在2019年的思考
  3. [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三)
  4. 第三章 线性代数回顾-机器学习老师板书-斯坦福吴恩达教授
  5. 一大批中文(BERT等)预训练模型等你认领!
  6. 这些分布式事务的解决方案,你都知道吗
  7. MYSQL性能调优及架构设计学习笔记-影响MYSQL性能的相关因素之实例分析
  8. LeetCode 1707. 与数组中元素的最大异或值(Trie树)
  9. Springboot之actuator配置不当漏洞RCE(jolokia)
  10. WampServer安装教程
  11. 吾爱破解论坛2021年11月11日,光棍节免费开放注册
  12. JAVA获取本机IP地址
  13. cups支持的打印机列表_更完整的CUPS打印机状态原因列表
  14. Java+spring基于ssm的基于SSM的高校奖学金助学金管理系统
  15. 关键字synchronized与volatile详解
  16. Android O 开机动画铃声
  17. Django-(6)
  18. 图片转字符画(python)
  19. 多台路由器,不同网段的设备之间如何互访?
  20. sql server远程连接时提示超时的解决办法

热门文章

  1. 融云 | 企业通讯录的设计与实现
  2. java cursor属性_cursor的使用 怎么使用cursor 中的数据
  3. Git统计代码行数;Java实现统计代码行数,忽略空行、注释行
  4. 区块链的起源、发展与繁荣
  5. html5 序列帧播放器,H5序列图片视频化播放
  6. C和指针知识点梳理一
  7. 给别人计算机office作业评语,Office操作题自动评分系统的总体评价
  8. GPS数据类型格式 NMEA协议
  9. Firefox扩展安装
  10. TOM收费邮箱稀缺终身会员邮靓号现收藏热潮