using System;

namespace Game
{
class Program
{
//用静态字段模拟全局变量
public static int[] Maps = new int[100];
//申明一个数组来存储玩家A和B
public static int[] PlayerPos = new int[2];
//存储玩家姓名
public static string[] PlayNames = new string[2];
//两个玩家的标记
static bool[] Flags = new bool[2];//默认是false
static void Main(string[] args)
{
GameShow();
#region 输入玩家姓名
Console.WriteLine("请输入玩家A的姓名");
PlayNames[0] = Console.ReadLine();
while (PlayNames[0] == "")
{
Console.WriteLine("不能为空,请重新输入");
PlayNames[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名");
PlayNames[1] = Console.ReadLine();
while (PlayNames[1] == PlayNames[0] || PlayNames[1] == "")
{
if (PlayNames[1] == "")
{
Console.WriteLine("不能为空,请重新输入");
PlayNames[1] = Console.ReadLine();
}
else
{
Console.WriteLine("不能和玩家A的姓名相同,请重新输入");
PlayNames[1] = Console.ReadLine();
}
}
#endregion
Console.Clear();
GameShow();
Console.WriteLine("{0}的士兵用A表示", PlayNames[0]);
Console.WriteLine("{0}的士兵用A表示", PlayNames[1]);
InitailMap();
DrawMap();
//让玩家AB同时开始玩游戏并结束
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}", PlayNames[0], PlayNames[1]);break;
}
if (Flags[1]==false)
{
PlayGame(1);
}
else
{
Flags[1] = false;
}
if (PlayerPos[1] >= 99)
{
Console.WriteLine("玩家{0}的赢了玩家{1}", PlayNames[1], PlayNames[0]); break;
}
}
Win();
Console.ReadKey();
}
/// <summary>
/// 游戏头
/// </summary>
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("*****飞行棋***********");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("**********************");
}

/// <summary>
/// 初始化地图
/// </summary>
public static void InitailMap()
{
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,4,2,3,7,8 };//暂停▲
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("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卐");
#region 第一横行
for (int i = 0; i < 30; i++)
{
//如果玩家A跟玩家B的坐标相同,并且都在这个地图上,画一个尖括号
Console.Write(DrawStringMap(i));
}
#endregion
//换行继续画竖着
Console.WriteLine();
#region 第一竖行
for (int i = 30; i < 35; i++)
{
for (int j = 0; j <= 28; 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();
}
/// <summary>
/// 画图中提取的一个抽象的方法
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static string DrawStringMap(int i)
{
string str = "";
//如果玩家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.Green; str = "□"; break;
case 1: Console.ForegroundColor = ConsoleColor.Blue; str = "◎"; break;
case 2: Console.ForegroundColor = ConsoleColor.Yellow; str = "☆"; break;
case 3: Console.ForegroundColor = ConsoleColor.Magenta; str = "▲"; break;
case 4: Console.ForegroundColor = ConsoleColor.Green; str = "卐"; break;
}
}
return str;
}
/// <summary>
/// 玩游戏
/// </summary>
/// <param name="playNumber"></param>
public static void PlayGame(int playNumber)
{
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("{0}按任意键开始掷骰子", PlayNames[playNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了{1}", PlayNames[playNumber], rNumber);
PlayerPos[playNumber] += rNumber;
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动", PlayNames[playNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了", PlayNames[playNumber]);
Console.ReadKey(true);
//玩家A有可能踩到了玩家B 方块 幸运轮盘 地雷 暂停 时空隧道
if (PlayerPos[playNumber] == PlayerPos[1 - playNumber])
{
Console.WriteLine("{0}踩到了{1}并使{1}退6格", PlayNames[playNumber], PlayNames[1 - playNumber], PlayNames[1 - playNumber]);
PlayerPos[playNumber] -= 6;
Console.ReadKey(true);
}
else
{
switch (Maps[PlayerPos[playNumber]])
{
case 0: Console.WriteLine("{0}踩到了方块 游戏继续", PlayNames[playNumber]); Console.ReadKey(true); break;
case 1:
Console.WriteLine("{0}踩到了幸运轮盘,请选择 1--交换位置 2--轰炸对方", PlayNames[playNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("{0}和{1}交换位置", PlayNames[playNumber], PlayNames[1 - playNumber]);
Console.ReadKey(true);
int 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]);

Console.ReadKey(true);
PlayerPos[1-playNumber] -= 6;
ChangePos();
Console.WriteLine("{0}退了6格",PlayNames[playNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");
input = Console.ReadLine();
}

}
break;
case 2: Console.WriteLine("{0}踩到了地雷退6格", PlayNames[playNumber]); Console.ReadKey(true); PlayerPos[playNumber] -= 6; ChangePos(); break;
case 3: Console.WriteLine("{0}踩到了暂停 暂停一回合", PlayNames[playNumber]); Flags[playNumber] = true; Console.ReadKey(true); break;
case 4: Console.WriteLine("{0}踩到了时空隧道前进10格", PlayNames[playNumber]); PlayerPos[playNumber] += 10; Console.ReadKey(true); ChangePos(); break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
//发送坐标移动时使用 防止AB跑出数组外
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;
}
}
/// <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#控制台玩飞行棋游戏的更多相关文章

  1. IT第十一天、第十二天、第十三天 - 数组的应用、飞行棋游戏的编写和总结

    NIIT第十一天 上午 多维数组 1.数组是引用数据类型 排序 1.冒泡排序法 2.类冒泡排序法 下午 飞行棋游戏 1.项目策划 2.项目规则确认 3.项目模块确认 晚上 1.飞行棋游戏,项目框架的编 ...

  2. C#飞行棋游戏

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

  3. C#基础:飞行棋游戏

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

  4. hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 浙江工商大学15年校赛E题 无邪的飞行棋 【经典背包】

    无邪的飞行棋 Time Limit 1s Memory Limit 64KB Judge Program Standard Ratio(Solve/Submit) 15.38%(4/26) Descr ...

  6. HTML5+JS 《五子飞》游戏实现(七)游戏试玩

    前面第一至第六章我们已经把<五子飞>游戏的基本工作都已经讲得差不多了,这一章主要是把所有的代码分享给大家,然后小伙伴们也可以玩一玩. 至于人机对战的我们放到后面讲进行分析. 试玩地址:ht ...

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

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

  8. C#基础篇六飞行棋

    飞行棋业务:我们要能够让2个玩家 在地图上 按照游戏规则 进行游戏 玩家类 变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中 方法:投骰子,移动 地图类 变量:地图数据数组 方法:初始化地图数据, ...

  9. C#小程序呢飞行棋设计分析

    C#小程序飞行棋,程序效果图 1.设计分析 这个程序界面大致分为四部分: ① 最上面游戏名字界面 ②信息提示区 ③游戏界面区 ④游戏操作提示区 2.分区设计实现 一.游戏界面显示区,由于只需要显示出图 ...

随机推荐

  1. formidable处理提交的表单或文件的简单介绍

    一般来说,客户端向服务端提交数据有GET和POST这两种方式,在之前的文章node.js当中的http模块与url模块的简单介绍当中我们可以知道通过req.url与url模块的配合处理可以快速得到客户 ...

  2. 如何巧妙地在基于 TCP Socket 的应用中实现用户注册功能?

    通常,在基于TCP的应用中(比如我开源的GGTalk即时通信系统),当TCP连接建立之后,第一个请求就是登录请求,只有登录成功以后,服务器才会允许客户端进行其它性质的业务请求.但是,注册用户这个功能比 ...

  3. 怎样快速找到某一行代码的git提交记录

    利用notepad++提高问题分析效率,以及快速找到某一行代码的git提交记录 1. 全目录搜索/替换 Notepad++是一款强大的文本编辑工具,当知道大概的关键词但不知道在哪个日志时可以使用not ...

  4. python编程系列---多线程共享全局变量出现了安全问题的解决方法

    多线程共享全局变量出现了安全问题的解决方法 当多线程共享全局变量时,可能出现安全问题,解决机制----互斥锁:即在在一段与全局变量修改相关的代码中,假设一个时间片不足以完成全局变量的修改,就在这段代码 ...

  5. 压敏电阻的保护作用—NDF达孚电子科技

    压敏电阻是常见的电子元器件之一,它的保护作用被大家熟知和运用.压敏电阻的主要用于在电路承受过压时进行电压钳位,吸收多余的电流以保护灵敏器件.压敏电阻的导电特性随着施加电压的变化呈非线性变化,它能保护电 ...

  6. 整洁的 Table View 代码

    Table view 是 iOS 应用程序中非常通用的组件.许多代码和 table view 都有直接或间接的关系,随便举几个例子,比如提供数据.更新 table view,控制它的行为以及响应选择事 ...

  7. Spring使用AspectJ开发AOP:基于Annotation

    基于 Annotation 的声明式 在 Spring 中,尽管使用 XML 配置文件可以实现 AOP 开发,但是如果所有的相关的配置都集中在配置文件中,势必会导致 XML 配置文件过于臃肿,从而给维 ...

  8. 小房子配置开发实例-IT资产管理(资产类管理)--开发设计过程

    小房子(Houselet)作为一个集开发和应用为一体的管理软件平台,通过数据库配置开发的方式来开发管理系统:目的在于辅助企业低成本快速建设管理系统.且系统为开放的,随时可以维护升级的,随企业管理的需要 ...

  9. django-模板之自定义模板路径(一)

    一般情况下我们的模板路径是位于app下的templates,我们可以根据实际情况自己定义模板的路径. 我们在与app的同级目录下建立一个templates,并在settings.py中进行路径配置. ...

  10. 怎样通过excel录入来批量造数据

    背景: 自动化测试除了验证系统功能外,还能够为测试人员根据测试要求造数据实现测试需要!但是一般的自动化测试,都是在编写脚本的时候,写死在程序里的.所以本文是为了在满足系统操作流程的基础上,根据测试的要 ...