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();
}
}
}

最新文章

  1. easyui datagrid 点击列表头排序出现错乱的原因
  2. @weakify, @strongify ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
  3. 5X + 2Y +Z = 50 的所有非负整数解
  4. YEdit
  5. 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
  6. QQ群共享文件下载很慢解决办法
  7. lua标签解析器
  8. DB2因表空间不够产生load表失败
  9. Enterprise Library深入解析与灵活应用(2): 通过SqlDependency实现Cache和Database的同步
  10. 《精通ASP.NET MVC5》第2章 第一个MVC应用程序
  11. C++ 11 笔记 (五) : std::thread
  12. hadoop安全模式
  13. Appium python自动化测试系列之Android UIAutomator终极定位(七)
  14. Selenium2Lib库之输入常用关键字实战
  15. Docker版本与安装介绍
  16. 安装openssh
  17. 第四节:详细讲解Java中的类和面向对象思想
  18. mac上生成目录结构
  19. HDU ACM 1856 More is better(并查集)
  20. Yii2.0页面提示消息

热门文章

  1. 实现下来ScrollView放大轮播图
  2. CentOS安装SVN服务器
  3. Linux常见查看硬件信息指令
  4. Time Consume Problem
  5. 读取properties配置文件的方法
  6. centos7中没有安装ifconfig命令的解决方法
  7. mysql 数据库引擎
  8. android 获取网络类型名称2G 3G 4G wifi
  9. 又见SpringMVC
  10. JAVA基础知识xml,date