using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
* 游戏规则:
* 1、如果玩家A踩到了玩家B,玩家B退6格;
* 2、踩到了地雷,退6格;
* 3、踩到了时空隧道,进10格;
* 4、踩到了幸运轮盘,1-交换位置,2-使对方退6格;
* 5、踩到了暂停,暂停一回合;
* 6、踩到了方块,什么都不干。
*/
namespace飞行棋
{
class Program
{
// 用静态字段来模拟全局变量
static int[] Maps = new int[100];
// 声明一个静态数组来存储玩家A和玩家B的坐标
static int[] PlayerPositions = new int[2];
// 声明一个静态数组来存储玩家A和玩家B是否暂停
static bool[] FlagOfPause = new bool[2]; // bool数组的默认值全是false
// 声明一个静态数组来存储玩家A和玩家的名字
static string[] PlayerNames = new string[2];
// 声明是否游戏结束的一个Flag变量,
// 值为-1时,游戏尚未结束;
// 值为0时,游戏结束,胜利者为PlayerNames[0]
// 值为1时,游戏结束,胜利者为PlayerNames[1]
static int WinnerNumber = -1;
static void Main(string[] args)
{
GameShow();
#region 输入玩家的姓名
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("请输入玩家A的姓名:");
PlayerNames[0] = Console.ReadLine();
while (PlayerNames[0] == "")
{
Console.WriteLine("玩家A的姓名不能为空,请重新输入");
PlayerNames[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名:");
PlayerNames[1] = Console.ReadLine();
while (PlayerNames[1] == "" || PlayerNames[1] == PlayerNames[0])
{
if (PlayerNames[1] == "")
{
Console.WriteLine("玩家B的姓名不能为空,请重新输入玩家B的姓名:");
}
else
{
Console.WriteLine("玩家B的姓名不能与玩家A的姓名一样,请重新输入玩家B的姓名:");
}
PlayerNames[1] = Console.ReadLine();
}
#endregion
// 玩家姓名输入Ok之后,我们首先应该清屏
Console.Clear(); // 清屏
GameShow();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("{0}的士兵用A表示\r\n{1}的士兵用B表示", PlayerNames[0], PlayerNames[1]);
InitialMap();
DrawMap();
#region 游戏开始
// 当玩家A跟玩家B没有一个人到达终点的时候,两个玩家不停地去玩游戏
while (PlayerPositions[0] < 99 && PlayerPositions[1] < 99)
{
if (FlagOfPause[0])
{
FlagOfPause[0] = false;
}
else
{
PlayGameOnce(0);
}
if (PlayerPositions[0] >= 99)
{
//Console.WriteLine("玩家{0}已经到达了终点", PlayerNames[0]);
continue;
学习的老赵的C#飞行棋例子代码 CSharp
最新推荐文章于 2022-11-13 12:58:29 发布