学习的老赵的C#飞行棋例子代码 CSharp

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;
          
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值