220224飞行器v1.0

using System;namespace AeroplaneChess
{class Program{//地图static int[] Maps = new int[100];//玩家A B坐标static int[] playerPos = new int[2];//玩家姓名static string[] playerNames = new string[2];//玩家回合标记static bool[] Flags = new bool[2];/// <summary>/// 主函数/// </summary>/// <param name="args"></param>static void Main(string[] args){//游戏封面GameShow();#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();}if (playerNames[1] == playerNames[0]){Console.WriteLine("玩家B姓名不能与玩家A相同,请重新输入");playerNames[1] = Console.ReadLine();}}#endregionConsole.Clear();//清屏GameShow();Console.WriteLine("{0}的飞机用A表示,{1}的士兵用B表示", playerNames[0], playerNames[1]);//初始化地图InitMap();//显示棋盘DrawMap();//胜利界面//游戏逻辑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;}}//whileWin();}//mian//static void Win(){Console.WriteLine(@"                                ■■■         ■■         ■■■■■ ■■ ■■     ■■■■■■■    ■■  ■■■■■ ■■ ■■     ■■■■■      ■■  ■■ ■■ ■■■■■■■■     ■■   ■■ ■■  ■■ ■■ ■■■■■■■■     ■■   ■■ ■■  ■■■■■■■  ■■    ■■■■■■■■ ■■ ■■  ■■ ■■    ■■    ■■■■■■■■ ■■ ■■  ■■ ■■  ■■■■■■     ■■■   ■■ ■■  ■■■■■  ■■■■■■    ■■■■■  ■■ ■■  ■■ ■■    ■■     ■■ ■■■■ ■■ ■■  ■■ ■■    ■■    ■■■ ■■ ■ ■■ ■■  ■■ ■■    ■■     ■  ■■      ■■  ■■ ■■ ■■■■■■■■     ■■      ■■  
■■ ■■■ ■■■■■■■■     ■■     ■■■  
■■ ■■               ■■     ■■   ");}/// <summary>/// 坐标限制/// </summary>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;}}/// <summary>/// 玩游戏/// </summary>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;ChangePos();//如果不限制 siwtch出界限会崩溃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]);Console.ReadKey(true);break;case 1:Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择1--交换位置 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[playerNumber] = temp;Console.WriteLine("交换完成!按下任意键继续游戏");Console.ReadKey(true);break;}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", playerNames[playerNumber], playerNames[1- playerNumber], playerNames[1- playerNumber]);Console.ReadKey(true);playerPos[1- playerNumber] -= 6;Console.WriteLine("玩家{0}退了6格!按下任意键继续游戏", playerNames[1- playerNumber]);Console.ReadKey(true);break;}else{Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对手");input = Console.ReadLine();}}break;case 2:Console.WriteLine("玩家{0}踩到了地雷,退6格", playerNames[playerNumber]);Console.ReadKey(true);playerPos[playerNumber] -= 6;break;case 3:Console.WriteLine("玩家{0}踩到了暂停,暂停一回合", playerNames[playerNumber]);Flags[playerNumber] = true;Console.ReadKey(true);break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道,前进十格", playerNames[playerNumber]);Console.ReadKey(true);playerPos[playerNumber] += 10;break;}//switch}//elseChangePos();Console.Clear();DrawMap();}/// <summary>/// 画地图/// </summary>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 < 35; 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 < 70; i++){Console.Write(DrawStringMap(i));Console.WriteLine();}#endregion#region 第三横行for (int i = 70; i < 100; i++){Console.Write(DrawStringMap(i));}Console.WriteLine();#endregion}/// <summary>/// 从画地图方法中抽象出来的一个方法/// </summary>/// <param name="i"></param>/// <returns></returns>static string DrawStringMap(int i){string str = "";//如果玩家坐标相同,画一个尖括号if (playerPos[0] == playerPos[1] && playerPos[1] == 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;}}return str;}/// <summary>/// 初始化棋盘/// </summary>static void InitMap(){//幸运轮盘◎1int[] luckytuen = { 6, 23, 40, 55, 69 };for (int i = 0; i < luckytuen.Length; i++){Maps[luckytuen[i]] = 1;}//地雷☆2int[] lanMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };for (int i = 0; i < lanMine.Length; i++){Maps[lanMine[i]] = 2;}//暂停▲3int[] pause = { 9, 27, 60, 93 };for (int i = 0; i < pause.Length; i++){Maps[pause[i]] = 3;}//时空隧道※4int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };for (int i = 0; i < timeTunnel.Length; i++){Maps[timeTunnel[i]] = 4;}}/// <summary>/// 画游戏头/// </summary>static void GameShow(){//背景色//Console.BackgroundColor = ConsoleColor.Red;//前景色 字体颜色Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("**************************");Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("**************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("**********飞行棋**********");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("*********20220203*********");Console.ForegroundColor = ConsoleColor.White;Console.WriteLine("************肖******V1.0**");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("**************************");}}
}

飞行棋游戏代码(C#)相关推荐

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

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

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

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

  3. C#基础(10)——飞行棋游戏

    1.打印游戏头 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

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

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

  5. 骑士飞行棋 C#代码详解

    最近看见一个骑士飞行棋的小游戏代码,感觉这个代码中将大多数C#的基础知识都运用到了,是一个新手检验学习成果的有效方法,特此将这个代码整理一遍.这是一个控制台程序.这是代码下载地址,代码中的注释非常详细 ...

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

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

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

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

  8. C#-飞行棋小游戏的前识 067

    1) Console.Title 这是Console类的一个属性用于设置控制台的标题 2)Console.Clear() 不用说是一个方法,用于清除控制台屏幕上的文字,只清除该代码中方法前面输出的内容 ...

  9. android游戏开发实例-可局域网对战的飞行棋(三)

    这一次,我们接着来谈AI策略和网络连接的架构. 在上一篇中我们设计了几个回合,我们简单来回忆一下这个流程: game_begin() -> turn_begin() -> 回合中 -> ...

最新文章

  1. 081_html5地理定位
  2. Java + MongoDB Hello World Example--转载
  3. 函数平移口诀_八年级数学下册:一次函数的图像,平移口诀是“上加下减,左加右减”...
  4. 自动备份网站和数据库打包并上传FTP服务器并删除前30天文件
  5. 【练习】树(Tree, UVa 548)给一棵点带权(权值各不相同)的二叉树的中序和后序遍历,找一个叶子使得它到根的路径上的权和最小。
  6. 设python中有模块m_Python 模块
  7. 复习Linux基本操作----常见指令
  8. 第二届太原理工大学程序设计新生赛预赛(公开赛)题解
  9. oracle 用户被锁定解决方法
  10. 多张图片合成一个pdf文件的操作方法
  11. java堆和栈 常量池_Java中栈、堆和常量池
  12. ArcGIS 计算椭球面积
  13. web技术分享| WebRTC控制摄像机平移、倾斜和缩放
  14. C# Abp框架入门系列文章(一)
  15. CSS设置background背景透明
  16. SPSSPRO模型归纳整理
  17. 发明专利名称的撰写原则和技巧总结
  18. COLA 4.0 - DDD项目实践
  19. 适用于Java开发人员的微服务:持续集成和持续交付
  20. Digital Pre-Distortion (数字预失真)以及用途

热门文章

  1. 一个简单的网页登陆(html)
  2. 矩阵键盘基于51(UcosII)计算器小项目
  3. Python开发【第六章】:面向对象
  4. mongo慢查询排查
  5. Android 中自定义ViewGroup实现流式布局的效果
  6. 【jqprint打印】js两种超简单的打印方法
  7. 怎样卸载计算机更新程序,windows10升级程序卸载怎么操作_windows10升级程序怎样卸载删除-win7之家...
  8. 霍尼韦尔摄像头ip地址修改_霍尼韦尔BA BNA设置
  9. 结算机网络的tracert和route命令
  10. 论文研读-社交媒体可视化-地图隐喻转发地图R-Map