C#基础知识---飞行棋小游戏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 飞行棋
{class Program{//静态数组模拟全局变量,地图,100static int[] Maps = new int[100]; //字段//玩家的位置static int[] PlayerPos = new int[2]; //字段//玩家的名字static string[] PlayerName = new string[2]; //字段//Flags为true,跳过一回合static bool[] Flags = new bool[2]; //字段static void Main(string[] args){GameShow();#region 输入玩家姓名Console.WriteLine("请输入玩家A的姓名");PlayerName[0] = Console.ReadLine();while (PlayerName[0] == ""){Console.WriteLine("玩家A姓名不能为空");Console.ReadLine();}Console.WriteLine("请输入玩家B的姓名");PlayerName[1] = Console.ReadLine();while (PlayerName[1] == "" || PlayerName[0] == PlayerName[1]){if (PlayerName[1] == ""){Console.WriteLine("玩家B姓名不能为空");}else{Console.WriteLine("玩家A和玩家B姓名不能相同");}Console.ReadLine();}#endregion//输完姓名清屏Console.Clear();InitailMap();DrawMap();#region //玩游戏while ((PlayerPos[0] < 99) && (PlayerPos[1] < 99)){if (Flags[0] == false){PlayGame(0);}else{//如果踩到了暂停,停一回合,把Flags设为假,下回合接着玩Flags[0] = false;}if (PlayerPos[0] >= 99){Console.WriteLine("{0}赢了", PlayerName[0]);}if (Flags[1] == false){PlayGame(1);}else{Flags[1] = false;}if (PlayerPos[1] >= 99){Console.WriteLine("{0}赢了", PlayerName[1]);}}#endregionConsole.WriteLine();Console.ReadKey();}//游戏头public static void GameShow(){Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("******************飞行棋******************");}//初始化地图,即初始化数组public static void InitailMap(){int[] luckyTurn = { 5, 13, 17, 33, 6, 23, 40, 55, 69, 83 };for (int i = 0; i < luckyTurn.Length; i++){Maps[luckyTurn[i]] = 1;}int[] landMine = { 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;}}//画地图,画出方块和关卡public static void DrawMap(){Console.WriteLine("{0}的士兵用A表示", PlayerName[0]);Console.WriteLine("{0}的士兵用B表示", PlayerName[1]);Console.WriteLine("图例:幸运轮盘○,地雷☆,暂停△,时空隧道卍");#region 第一横行for (int i = 0; i < 30; i++){Console.Write(DrawStringMap(i));}#endregion//画完第一横行换行Console.WriteLine();#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));}#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));}#endregion//画完第三横行换行Console.WriteLine();}//画关卡 返回一个关卡public static string DrawStringMap(int i){string str = "";//玩家A踩到了玩家B,玩家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";}elseswitch (Maps[i]){case 0:Console.ForegroundColor = ConsoleColor.Yellow;str = "□";break;case 1:Console.ForegroundColor = ConsoleColor.Red;str = "○";break;case 2:Console.ForegroundColor = ConsoleColor.White;str = "★";break;case 3:Console.ForegroundColor = ConsoleColor.Blue;str = "△";break;case 4:Console.ForegroundColor = ConsoleColor.Green;str = "卍";break;}return str;}//玩游戏public static void PlayGame(int playNumber){Random r = new Random();int rNumber = r.Next(1, 7);Console.WriteLine("{0}按任意键开始掷骰子", PlayerName[playNumber]);Console.ReadKey(true);Console.WriteLine("{0}掷出了{1}点", PlayerName[playNumber], rNumber);PlayerPos[playNumber] += rNumber;Console.ReadKey(true);Console.WriteLine("{0}按任意键开始行动", PlayerName[playNumber]);Console.ReadKey(true);Console.WriteLine("{0}行动完了", PlayerName[playNumber]);Console.ReadKey(true);if (PlayerPos[playNumber] == PlayerPos[1 - playNumber]){Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退六格", PlayerName[playNumber], PlayerName[1 - playNumber], PlayerName[1 - playNumber]);PlayerPos[1 - playNumber] -= 6;}else{switch (Maps[PlayerPos[playNumber]]){case 0: Console.WriteLine("{0}踩到了方块,安全", PlayerName[playNumber]);Console.ReadKey(true);break;case 1: Console.WriteLine("{0}踩到了幸运轮盘,选择1交换位置,2轰炸对方", PlayerName[playNumber]);string input = Console.ReadLine();while (true){if (input == "1"){Console.WriteLine("{0}选择跟{1}交换位置", PlayerName[playNumber], PlayerName[1 - playNumber]);Console.ReadKey(true);int temp = PlayerPos[playNumber];PlayerPos[playNumber] = PlayerPos[1 - playNumber];PlayerPos[1 - playNumber] = temp;Console.WriteLine("交换成功");break;}else if (input == "2"){Console.WriteLine("{0}选择轰炸{1}", PlayerName[playNumber], PlayerName[1 - playNumber]);Console.ReadKey(true);PlayerPos[1 - playNumber] -= 6;Console.WriteLine("{0}退了六格", PlayerName[1 - playNumber]);Console.ReadKey(true);break;}else{Console.WriteLine("只能输入1或2");input = Console.ReadLine();}}break;case 2: Console.WriteLine("{0}踩到了地雷,退六格", PlayerName[playNumber]);Console.ReadKey(true);PlayerPos[playNumber] -= 6;break;case 3: Console.WriteLine("{0}踩到了暂停,跳过一回合", PlayerName[playNumber]);Flags[playNumber] = true;Console.ReadKey(true);break;case 4: Console.WriteLine("{0}踩到了时空隧道,前进十格", PlayerName[playNumber]);Console.ReadKey(true);PlayerPos[playNumber] += 10;break;default:break;}}ChangePos();Console.Clear();DrawMap();}//限定位置,防止出界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#基础知识---飞行棋小游戏相关推荐
- C# 实现飞行棋小游戏
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- C# 飞行棋小游戏 (控制台应用)
目录 C# 控制台飞行棋小游戏 简要介绍 游戏画面 规则说明 游戏代码 `Entry.cs` `Operate.cs` `Map.cs` `Player.cs` 其他问题 C# 控制台飞行棋小游戏 简 ...
- C#实现一个控制台飞行棋小游戏(附源码)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 【全栈计划 —— 编程语言之C#】 C# 实现双人飞行棋小游戏
文章目录 前言 项目结构流程图 项目实现 一.游戏开始界面 二.初始化游戏地图 三.绘制飞行棋地图 四.玩游戏具体逻辑 ① 创建两个玩家角色 ② 具体走到每个关卡触发的结果 ③ 判断胜利 ④ 回首调优 ...
- 记录基础学习第二_小项目_飞行棋小游戏
飞行棋项目: 1.游戏头(要求每一个句子显示不同的颜色 ) //这里用到了Console类中的ForegroundColor属性 取值是枚举类型ConsoleColor中的值 ...
- C#基础-飞行棋小游戏
直接贴代码 class Program {static int[] Maps = new int[100];static int[] PlayerPos = new int[2];//玩家A,B的坐标 ...
- 【C#】制作简单的飞行棋小游戏
飞行棋双人小游戏 目标:实现飞行棋游戏基础功能 玩家在地图触发道具: 获得道具,可以进行一次选择 1–交换位置 2–让对方退随机格子 踩到炸弹,让对方暂停一回合 乘上了飞机,前进10格 进入隧道,将随 ...
- python飞行棋小游戏
import random # 地图初始坐标 Maps = [0] *100 # 玩家A和玩家B的初始坐标 PlayerPos = [0]*2 # 存储玩家姓名 playerNames = [&quo ...
- C#控制台实现飞行棋小游戏
游戏标题 static void ShowTitle(){Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("*** ...
最新文章
- (C++)高精度整数的存储、读入、比较和四则运算
- C语言之free函数及野指针
- llinux 调整swap方法
- 如何在不亏本的情况下构建道德数据科学系统?
- php 删除某个文件夹,Php删除指定文件与文件夹的方法
- 1分钟了解区块链的本质
- Mongo 查询(可视化工具)
- java蓝桥杯dfs_第七届 蓝桥杯决赛 Java B组 打靶 解题报告(DFS,回溯,全排列)-Go语言中文社区...
- spring boot 初步学习
- 苹果cms后台微信小程序影视源码-带视频教程
- 单目视觉里程计的尺度问题的疑问?
- ffmpeg之图片转gif
- 【爬坑日记】vue中传props时默认为Boolean问题
- vue 日期前面加0_NutUI - 京东开源的轻量级移动端Vue组件库
- windows10改变鼠标指针
- 删除Windows远程桌面连接记录 和 删除Windows凭据
- openwrt环境下,使用externel commissioning组网openthread
- 如何打出日语中的叠字符号「々」
- vue的history模式,页面刷新404,以及引入得第三方插件或者JS路径错误的解决办法
- php zend optimizer 解密,zend guard对php代码加密 zend optimizer解析