using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Pachee
{
class Program
{
#region 静态字段
// 关卡数量
public static int[] Maps = new int[];
// 玩家坐标
public static int[] PlayerPos = new int[];
// 玩家名称
public static string[] PlayerNames = new string[];
// 判断玩家是否暂停
public static bool[] Flags = new bool[];
#endregion /// <summary>
/// 输出游戏头
/// </summary>
public static void ShowGame()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("***C#基础练习:飞行棋项目***");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("****************************");
}
/// <summary>
/// 接受用户输入的游戏名称,判断是否合法
/// </summary>
/// <returns>游戏名称</returns>
public static string[] InputPlayerNames()
{
PlayerNames[] = "";
PlayerNames[] = "";
Console.ForegroundColor = ConsoleColor.White;
while (PlayerNames[] == "")
{
Console.Write("Please enter the name of game A player: ");
PlayerNames[] = Console.ReadLine().Trim();
if (PlayerNames[] == "")
{
Console.WriteLine("A player name cannot be empty, please enter again.");
continue;
}
break;
}
while (PlayerNames[] == "" || PlayerNames[] == PlayerNames[])
{
Console.Write("Please enter the name of game B player: ");
PlayerNames[] = Console.ReadLine().Trim();
if (PlayerNames[] == "")
{
Console.WriteLine("B player name cannot be empty, please enter again.");
continue;
}
else if (PlayerNames[] == PlayerNames[])
{
Console.WriteLine("The player name cannot be the same as the player A B, please enter again.");
continue;
}
break;
}
return PlayerNames;
}
/// <summary>
/// 初始化地图,改变默认的地图坐标类型
/// 0:方块
/// 1:轮盘
/// 2:地雷
/// 3:暂停
/// 4:隧道
/// </summary>
public static void InitailMap()
{
#region 轮盘
int[] luckTrun = { , , , , , };
for (int i = ; i < luckTrun.Length; i++)
{
Maps[luckTrun[i]] = ;
}
#endregion #region 地雷
int[] landMine = { , , , , , , , , };
for (int i = ; i < landMine.Length; i++)
{
Maps[landMine[i]] = ;
}
#endregion #region 暂停
int[] pause = { , , , };
for (int i = ; i < pause.Length; i++)
{
Maps[pause[i]] = ;
}
#endregion #region 隧道
int[] timeTunnel = { , , , , , , };
for (int i = ; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = ;
}
#endregion
}
/// <summary>
/// 设定当前坐标的类型
/// </summary>
/// <param name="i">坐标</param>
/// <returns>坐标类型</returns>
public static string DrawStringMap(int i)
{
string str = null;
if (PlayerPos[] == PlayerPos[] && PlayerPos[] == i)
{
str = "<>";
}
else if (PlayerPos[] == i)
{
str = "A";
}
else if (PlayerPos[] == i)
{
str = "B";
}
else
{
switch (Maps[i])
{
case :
Console.ForegroundColor = ConsoleColor.Yellow;
str = "□";
break;
case :
Console.ForegroundColor = ConsoleColor.Blue;
str = "◎";
break;
case :
Console.ForegroundColor = ConsoleColor.Green;
str = "☆";
break;
case :
Console.ForegroundColor = ConsoleColor.Red;
str = "▲";
break;
case :
Console.ForegroundColor = ConsoleColor.Cyan;
str = "卐";
break;
}
}
return str;
}
/// <summary>
/// 生成所有坐标
/// </summary>
public static void DrawMap()
{
Console.WriteLine("Legend: LuckTrun<◎> landMine<☆> Pause<▲> timeTunnel<卐>"); #region 第一橫行
for (int i = ; i < ; i++)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion #region 第一竖行
for (int i = ; i < ; i++)
{
for (int j = ; j <= ; j++)
{
Console.Write(" ");
}
Console.Write(DrawStringMap(i));
Console.WriteLine();
}
#endregion #region 第二橫行
for (int i = ; i >= ; i--)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion #region 第二竖行
for (int i = ; i < ; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion #region 第三橫行
for (int i = ; i <= ; i++)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion
}
/// <summary>
/// 判断坐标是否超出范围
/// </summary>
public static void ChangePos()
{
#region Player A
if (PlayerPos[] < )
{
PlayerPos[] = ;
}
if (PlayerPos[] > )
{
PlayerPos[] = ;
}
#endregion #region Player B
if (PlayerPos[] < )
{
PlayerPos[] = ;
}
if (PlayerPos[] > )
{
PlayerPos[] = ;
}
#endregion
}
/// <summary>
/// 踩到轮盘时,选择功能
/// </summary>
/// <param name="input">玩家的选择</param>
/// <param name="player">玩家标示</param>
public static void PlayerSelect(string input, int player)
{
while (true)
{
if (input == "")
{
Console.WriteLine("Player {0} select and {1} swap places.", PlayerNames[player], PlayerNames[ - player]);
int temp = PlayerPos[player];
PlayerPos[player] = PlayerPos[ - player];
PlayerPos[ - player] = temp;
Console.WriteLine("Swap complete, press any key continue.");
Console.ReadKey(true);
break;
}
else if (input == "")
{
Console.WriteLine("Player {0} select bombing {1}, Player {2} back to 6.", PlayerNames[player], PlayerNames[ - player], PlayerNames[ - player]);
PlayerPos[ - player] -= ;
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("Can only select: 1--Swap places 2--bombing: ");
input = Console.ReadLine();
}
}
}
/// <summary>
/// 进行游戏
/// </summary>
/// <param name="player">玩家标示位</param>
public static void PlayGame(int player)
{
Random r = new Random();
int next = r.Next(, );
Console.WriteLine("{0} press any key to start rolling the dice.", PlayerNames[player]);
Console.ReadKey(true);
Console.WriteLine("{0} Throw out of {1}", PlayerNames[player], next);
PlayerPos[player] += next;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0} press any key to start action.", PlayerNames[player]);
Console.ReadKey(true);
Console.WriteLine("{0} action complete.", PlayerNames[player]);
Console.ReadKey(true);
// Player A 有可能踩到: Player B、方块、轮盘、地雷、暂停、隧道
if (PlayerPos[player] == PlayerPos[ - player])
{
Console.WriteLine("Player {0} step on {1}, {2} back to 6.", PlayerNames[player], PlayerNames[ - player], PlayerNames[ - player]);
PlayerPos[ - player] -= ;
Console.ReadKey(true);
}
else
{
switch (Maps[PlayerPos[player]])
{
case :
Console.WriteLine("Player {0} step on Square, safe.", PlayerNames[player]);
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a LuckTrun, please select: 1--Swap places 2--bombing: ", PlayerNames[player]);
string input = Console.ReadLine().Trim();
PlayerSelect(input, player);
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a LandMine, back to 6", PlayerNames[player]);
PlayerPos[player] -= ;
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a Pause, to suspend a round.", PlayerNames[player]);
Console.ReadKey(true);
Flags[player] = true;
break;
case :
Console.WriteLine("Player {0} step on a TimeTunnel, forward 10.", PlayerNames[player]);
PlayerPos[player] += ;
Console.ReadKey();
break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
static void Main(string[] args)
{
ShowGame();
InputPlayerNames();
Console.WriteLine("Player {0} is A.", PlayerNames[]);
Console.WriteLine("Player {0} is B.", PlayerNames[]);
InitailMap();
DrawMap(); while (PlayerPos[] < && PlayerPos[] < )
{
#region A
if (Flags[] == false)
{
PlayGame();
}
else
{
Flags[] = false;
}
#endregion
#region B
if (Flags[] == false)
{
PlayGame();
}
else
{
Flags[] = false;
}
#endregion
}
#region 判断玩家胜利 if (PlayerPos[] == )
{
Console.Clear();
Console.WriteLine("Player {0} Win.", PlayerNames[]);
}
if (PlayerPos[] == )
{
Console.Clear();
Console.WriteLine("Player {0} Win.", PlayerNames[]);
}
#endregion Console.ReadKey();
}
}
}

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; namespace Game{ class Program { //用静态字段模拟全局变量 public static int[] Maps = new int[100]; ...

  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. C#基础篇六飞行棋

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

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

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

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

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

  9. HTML5+JS 《五子飞》游戏实现(三)页面和棋盘棋子

    前面两节,我们已经对<五子飞>有个初步的认识,对走棋路线也有了基本的了解,现在里沃特继续跟大家分享HTML页面,另外把棋盘棋子也画出来. 演示地址:http://www.lyout.com ...

随机推荐

  1. javascript的defer和async的区别。

    我们常用的script标签,有两个和性能.js文件下载执行相关的属性:defer和async defer的含义[摘自https://developer.mozilla.org/En/HTML/Elem ...

  2. javascript浏览器检测

    <script type="text/javascript">   /**  * 获取浏览器类型以及版本号  * 支持国产浏览器:猎豹浏览器.搜狗浏览器.傲游浏览器.3 ...

  3. JAVA Shallow heap & Retained heap

    最近在研究内存泄漏的问题,在使用MAT工具中发现了Shallow heap & Retained heap,不懂. 然后在网上找了一些资料. Shallow Size 对象自身占用的内存大小, ...

  4. ListView和Adapter数据适配器的简单介绍

    ListView 显示大量相同格式数据 常用属性: listSelector            listView每项在选中.按下等不同状态时的Drawable divider            ...

  5. iOS 如何使用Safari浏览器打开app

    1.首先在info.plist添加一个键值对,如下图 或 2.在appdelegate.m文件如下方法写代码 -(BOOL)application:(UIApplication*)app openUR ...

  6. SQLSERVER常见系统函数之字符串函数(一)

    好久没有写博客了,这段时间准备写一下字符串函数 QQ群: 499092562:欢迎交流 字符串函数: 1.LEN(需要获取长度的字符串) 返回:字符串的长度 示例: SELECT LEN('小搬运工很 ...

  7. Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解

    转载:http://freeloda.blog.51cto.com/2033581/1288553 大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负 ...

  8. JavaScript—从数组的indexOf方法深入——Object的Property机制。

    在js中,可以说万物皆对象(object),一个数组也是一个对象(array). 很多对象都有很多很方便的方法 比如数组的push,concat,slice等等,但是如果一些对象,它没有实现这些方法, ...

  9. JAVA NIO Socket通道

      DatagramChannel和SocketChannel都实现定义读写功能,ServerSocketChannel不实现,只负责监听传入的连接,并建立新的SocketChannel,本身不传输数 ...

  10. 安装.NET Framework进度条卡住不动的解决方案

    VS在安装之前需要安装.NET Framework,我安装的是4.0版本.但是安装进度条到一半左右时就卡住不动了.前前后后重试多次,还有几次重新开机,但都没用. 开始还以为是安装的系统有问题.后来在网 ...