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. 针对JS经典题型对全局变量及局部变量的理解浅谈

    第一次写博,还蛮激动... 看到了三题经典题型,就我目前的认识对此题进行总结.如有错误,敬请指正 首先,我们先明确一下JS引擎的工作步骤: js引擎工作分为两步: 1.将这个js中的变量和函数声明保存 ...

  2. Android之RecyclerView的原生Bug-Inconsistency detected. Invalid view holder adapter positionViewHolder{a1bbfa3 position=2 id=-1, oldPos=-1, pLpos:-1 no parent}

    今天在运行自己编写的App时,突然发现App在运行时闪退,然后就查看了Android Studio的Log,发现了这个错误,上网查了一下,才知道是RecyclerView的原生Bug,在数据更新时会出 ...

  3. [C#6] 1-using static

    0. 目录 C#6 新增特性目录 1. 老版本的代码 1 using System; 2 3 namespace csharp6 4 { 5 internal class Program 6 { 7 ...

  4. Entity Framework之IQueryable和list本地集合

    我们来说一下Iqueryable集合和List等本地集合的区别,下面我们通过建立一个简单的例子来学习这个知识点,直接进入主题吧 1.首先对比一下两段代码?看一下有什么结果: (1) 第一段代码如图所示 ...

  5. freeswitch对接其它SIP设备

    这几天用到freeswitch对接其它设备方面的知识,这里整理下,也方便我以后查阅. 操作系统:debian8.5_x64 freeswitch 版本 : 1.6.8 一.freeswitch作为被叫 ...

  6. MySQL 博客文章目录(2016-08-20更新)

    1 MySQL安装配置 Linux MySQL源码安装缺少ncurses-devel包 Linux平台卸载MySQL总结 Linux 卸载mysql-libs包出现错误 2  MySQL管理配置 My ...

  7. Linux下MySQL慢查询分析mysqlsla安装使用

    说明: 操作系统:CentOS 5.X 64位 MySQL版本:mysql-5.5.35 MySQL配置文件:/etc/my.cnf MySQL 数据库存放目录:/data/mysql 实现目的:开启 ...

  8. Redis学习笔记~Redis事务机制与Lind.DDD.Repositories.Redis事务机制的实现

    回到目录 Redis本身支持事务,这就是SQL数据库有Transaction一样,而Redis的驱动也支持事务,这在ServiceStack.Redis就有所体现,它也是目前最受业界认可的Redis ...

  9. js控制div滚动条,滚动滚动条使div中的元素可见并居中

    1.html代码如下 <div id="panel"> <div id="div1"></div> <div id=& ...

  10. 最短路径算法-Dijkstra

    Dijkstra是解决单源最短路径的一般方法,属于一种贪婪算法. 所谓单源最短路径是指在一个赋权有向图中,从某一点出发,到另一点的最短路径. 以python代码为例,实现Dijkstra算法 1.数据 ...