using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace demo1
{/** 游戏规则* 玩家A踩到了玩家B 玩家B退6格* 踩到地雷 退6格* 踩到时空隧道 进10格* 踩到幸运轮盘 1 交换位置 2 轰炸对方 使对方退6格* 踩到暂停 暂停一回合* 踩到方块 什么都不干*/class Program{// 静态变量模拟全局变量static int[] Maps = new int[100];// 静态数组 存储玩家A和玩家B的位置static int[] PlayerPos = new int[2];// 存储两个玩家的姓名static string[] PlayerName = new string[2];// 用来暂停, 默认是falsestatic bool[] Flag = new bool[2];static void Main(string[] args){GameShow();// 输入玩家姓名InputName();// 玩家姓名输入之后, 清屏Console.Clear();GameShow();Console.WriteLine("{0}的玩家用A表示\n{1}的玩家用B表示", PlayerName[0], PlayerName[1]);// 初始化地图InitialMap();// 绘制地图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.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("玩家{0}赢了玩家{1}, 率先到达终点!!!", PlayerName[0], PlayerName[1]);break;}if (Flag[1] == false){PlayGame(1);}else{Flag[1] = false;}if (PlayerPos[1] >= 99){Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("玩家{0}赢了玩家{1}, 率先到达终点!!!", PlayerName[1], PlayerName[0]);break;}}// whileWin();Console.ReadKey();}/// <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(" ■■ ■■■■■■■■   ■     ■■■");}/// <summary>/// 画游戏头/// </summary>public static void GameShow(){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("**********************");Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("**********************");Console.ForegroundColor = ConsoleColor.DarkMagenta;Console.WriteLine("**********************");Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine("***自制飞行棋小游戏***");Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("**********************");Console.ForegroundColor = ConsoleColor.Gray;Console.WriteLine("**********************");}/// <summary>/// 初始化地图/// </summary>public static void InitialMap(){int[] luckyturn = { 6, 23, 40, 55, 69, 83 }; // 幸运轮盘◎for (int i = 0; i < luckyturn.Length; 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]] = 4;}/// <summary>/// 绘制地图/// </summary>public static void DrawMap(){Console.WriteLine("图例:幸运轮盘:◎   地雷:☆   暂停:▲   时空隧道:〓");#region 第一横行for (int i = 0; i <= 29; i++){Console.Write(DrawStringMap(i));}#endregion// 换行Console.WriteLine();#region 第一竖行for (int i = 30; i <= 34; 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));}#endregion// 换行Console.WriteLine();#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();} // DrawMap/// <summary>/// 绘制地图图形/// </summary>/// <param name="i"></param>/// <returns></returns>public static string DrawStringMap(int i){string str = "";#region 画图// 玩家A与玩家B坐标相同,并且都在地图上 画<>if (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.Blue;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Yellow;str = "◎";break;case 2:Console.ForegroundColor = ConsoleColor.Red;str = "☆";break;case 3:Console.ForegroundColor = ConsoleColor.Green;str = "▲";break;case 4:Console.ForegroundColor = ConsoleColor.Cyan;str = "〓";break;} // switch} // else#endregionreturn str;} // DrawStringMap/// <summary>/// 玩家姓名输入/// </summary>public static void InputName(){#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[1] == ""){Console.WriteLine("玩家B姓名不能为空, 请重新输入: ");}else{Console.WriteLine("玩家B的姓名不能与玩家A相同, 请重新输入: ");}PlayerName[1] = Console.ReadLine();}#endregion}/// <summary>/// 玩游戏/// </summary>public static void PlayGame(int playerNum){Random r = new Random();int rNum = r.Next(1, 7);Console.WriteLine("玩家{0}按任意键开始掷骰子", PlayerName[playerNum]);// 将按下的键不显示在窗口中Console.ReadKey(true);Console.WriteLine("玩家{0}掷出了{1}", PlayerName[playerNum], rNum);PlayerPos[playerNum] += rNum;ChangePos();Console.ReadKey(true);Console.WriteLine("玩家{0}按任意键开始行动", PlayerName[playerNum]);Console.ReadKey(true);Console.WriteLine("玩家{0}行动完了", PlayerName[playerNum]);Console.ReadKey(true);// 玩家A踩到了玩家B 方块 幸运轮盘 地雷 暂停 时空隧道if (PlayerPos[playerNum] == PlayerPos[1 - playerNum]){Console.WriteLine("玩家{0}踩到了玩家{1}, 玩家{2}退6格", PlayerName[playerNum], PlayerName[1 - playerNum], PlayerName[1 - playerNum]);PlayerPos[1 - playerNum] -= 6;ChangePos();Console.ReadKey(true);}else // 踩到了其他关卡上{// 玩家坐标switch (Maps[PlayerPos[playerNum]]){case 0:Console.WriteLine("玩家{0}踩到方块,安全", PlayerName[playerNum]);Console.ReadKey(true);break;case 1:Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择1-交换位置 2-轰炸对方", PlayerName[playerNum]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("玩家{0}选择与玩家{1}交换位置", PlayerName[playerNum], PlayerName[1 - playerNum]);Console.ReadKey(true);int tmp = PlayerPos[playerNum];PlayerPos[playerNum] = PlayerPos[1 - playerNum];PlayerPos[1 - playerNum] = tmp;Console.WriteLine("交换成功!!!按任意键继续游戏!!!!");Console.ReadKey(true);break;}else if (input == "2"){Console.WriteLine("玩家{0}选择轰炸玩家{1}, 玩家{2}退6格", PlayerName[playerNum], PlayerName[1 - playerNum], PlayerName[1 - playerNum]);Console.ReadKey(true);PlayerPos[1 - playerNum] -= 6;ChangePos();Console.WriteLine("玩家{0}已经退了6格", PlayerName[1 - playerNum]);Console.ReadKey(true);break;}else{Console.WriteLine("只能输入1或2 1-交换位置 2-轰炸对方");input = Console.ReadLine();}}break;case 2:Console.WriteLine("玩家{0}踩到了地雷 退6格", PlayerName[playerNum]);Console.ReadKey(true);PlayerPos[playerNum] -= 6;ChangePos();break;case 3:Console.WriteLine("玩家{0}踩到了暂停 暂停一回合", PlayerName[playerNum]);Console.ReadKey(true);Flag[playerNum] = true;break;case 4:Console.WriteLine("玩家{0}踩到了时空隧道 前进10格", PlayerName[playerNum]);Console.ReadKey(true);PlayerPos[playerNum] += 10;ChangePos();break;}// switch}// elseChangePos();// 清屏Console.Clear();DrawMap();} // PlayGame/// <summary>/// 当玩家坐标发生改变的时候/// </summary>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# 飞行棋小游戏 (控制台应用)

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

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

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

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

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

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

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

  5. python飞行棋小游戏

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

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

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

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

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

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

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

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

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

最新文章

  1. Linux如何在任务栏显示时间,在MFC[转载]在MFC状态栏显示时间 状态栏显示时间
  2. 6. Qt 信号与信号槽(8)实例分析
  3. Ubuntu系统目录结构
  4. 老公贷款还不上,妻子有偿还责任吗?
  5. Springboot异步任务线程池
  6. 图论 —— 环与块 —— 连通块的计数
  7. DB主从一致性架构优化4种方法
  8. java pojo生成_生成代码的代码 之 POJO生成器
  9. Layer 引入自定义模块
  10. Golang 大杀器之性能剖析 PProf
  11. [Mac A]为什么国外程序员爱用 Mac?
  12. 激光点云常用数据集整理
  13. html5鼠标悬停下拉列表,HTML5与CSS3中鼠标悬停会有下拉列表
  14. 实验12 网络资源共享
  15. python 阮一峰_阮一峰关于 Javascript 中闭包的解读是否正确?
  16. Unity游戏画面参数解析与应用:垂直同步、动态模糊、抗锯齿
  17. 开发常用下载地址收藏
  18. ueditor编辑器右键粘贴、复制不能用的解决办法
  19. 淘宝接口 TopAPi
  20. 基于Java的图书馆管理系统

热门文章

  1. vscode能写winform窗体吗_VSCode——愉快的写C#
  2. 如何实现上传多个图片并依次展示_如何在一张ppt中插入多张图片并能依次播放...
  3. 初中信息技术说课稿_小学信息课说课稿范文(精选6篇)
  4. 如何快速搭建一个简单图像搜索引擎
  5. 压缩软件大比拼历史回顾:ZIP与RAR
  6. 面试官系列 - LeetCode链表知识点题型总结
  7. Autosar MCAL MCU配置时钟-基于cfg
  8. 百度脑图-便捷的思维工具
  9. Log4j“核弹级”bug修复
  10. 「Nescafé26」 Freda的传呼机 【树上倍增+图论】