nwdnwdnwd 2014-12-05 02:29 采纳率: 0%
浏览 1848

关于骑士飞行棋的问题

我做到这一步了,随机产生A的数,为什么A不移动

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 飞行棋
{
    class Program
    {
        static int[] Map = new int[100];//存地图
        static int[] playerPos = { 4,0 };//playerPos[0]存A的下标,playerPos[1]存B的下标


        static void Main(string[] args)
        {
            //下面的数组存储我们游戏地图各种关卡
            //数组的下标为0的元素对应地图上的第1格  下标为1的元素对应地图上的第2格,下标为N的对应第N+1格
            //在数组中用   1 表示幸运轮盘◎
            //            2 地雷☆
            //            3 暂停▲
            //            4 时空隧道卍
            //            0  表示普通

            int[] Map = new int[100];

            Random r = new Random();//r是产生一个随机数的
            int step = 0;//存放临机产生一个随机数
            string[] names = new string[2];//names[0]存玩家A的姓名,names[1]存玩家B的姓名
            ShowUI();
            Console.WriteLine("请输入玩家A姓名:");
            names[0] = Console.ReadLine();
            while (names[0] == "")//判断姓名是否为空
            {
                Console.WriteLine("玩家A的姓名不能为空,请重新输入!");
                names[0] = Console.ReadLine();
            }
            Console.WriteLine("请输入玩家B的姓名:");
            names[1] = Console.ReadLine();
            while (names[1] == "" || names[1] == names[0])
              {
                if (names[1] == "")
                {
                    Console.WriteLine("玩家B的姓名不能为空,请重新输入!");
                    names[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("该姓名已被玩家A使用,请重新输入!");
                    names[1] = Console.ReadLine();
                }
            }
            Console.Clear();
            ShowUI();
            Console.WriteLine("对战开始……");
            Console.WriteLine("{0}用A来表示", names[0]);
            Console.WriteLine("{0}用B来表示", names[1]);
            Console.WriteLine("如果AB使用同一位置,用<>来表示");
            IntialMap();//初始化地图
            DrawMap();//绘制地图
            Console.WriteLine();
            Console.WriteLine("开始游戏…………");

            //这个循环中让A和B轮流掷骰子,当玩家A和玩家B的值>=99时,则结束循环。
            //循环条件就是
            while (playerPos[0] < 99 && playerPos[1] < 99)
            {
                #region//玩家A
                Console.WriteLine("{0}按任意键开始掷骰子……", names[0]);
                Console.ReadKey(true);
                step = r.Next(1, 7);
                Console.WriteLine("{0}掷出了{1}", names[0], step);
                Console.WriteLine("按任意键开始行动……");
                Console.ReadKey(true);
                playerPos[0] +=  step;

                #endregion

                #region//玩家B

                #endregion
            }










            Console.ReadKey();
        }
        /// <summary>
        /// 用于绘制界面
        /// </summary>
        static void ShowUI()
        {
            Console.WriteLine("****************************************");
            Console.WriteLine("*                                      *");
            Console.WriteLine("*        骑   士   飞   行   琪        *");
            Console.WriteLine("*                                      *");
            Console.WriteLine("****************************************");

        }
        /// <summary>
        /// 对地图中的关卡进行初始化
        /// </summary>
        static void IntialMap()
        {
            //用于存储地图中地图的下标
            int[] luckyTurn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎
            int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆
            int[] pause = { 9, 27, 60, 93 };//暂停▲
            int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卍
            for (int i = 0; i < luckyTurn.Length; i++)
            {

                Map[luckyTurn[i]] = 1;
            }
            for (int i = 0; i < landMine.Length; i++)
            {
                Map[landMine[i]] = 2;
            }
            for (int i = 0; i < pause.Length; i++)
            {
                Map[pause[i]] = 3;
            }
            for (int i = 0; i < timeTunnel.Length; i++)
            {
                Map[timeTunnel[i]] = 4;
            }


        }
        /// <summary>
        /// 获得第POS坐标上应该绘制的图案
        /// </summary>
        /// <param name="pos">要绘制的坐标</param>
        /// <returns></returns>
        static string GetMapString(int pos)
        {
            string resule = "";

            if (playerPos[0] == pos && playerPos[1] == pos)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                resule = "<>";

            }
            else if (playerPos[0] == pos)//A当前画的格上
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                resule = "A";
            }
            else if (playerPos[1] == pos)//B在当前的格上
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                resule = "B";
            }
            else
            {
                switch (Map[pos])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.White;
                        resule = "□";
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        resule = "◎";
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Green;
                        resule = "☆";
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        resule = "▲";
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        resule = "卍";
                        break;
                }
            }
            return resule;

        }
        /// <summary>
        /// 画地图的方法
        /// </summary>
        static void DrawMap()
        {
            Console.WriteLine("图例:运轮盘◎2 地雷☆  3暂停▲    时空隧道卍");

            //这是第一行
            for (int i = 0; i <= 29; i++)
            {
                Console.Write(GetMapString(i));
            }
            Console.WriteLine();
            //这是第二行
            for (int i = 30; i <= 34; i++)
            {
                for (int j = 0; j < 58; j++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine(GetMapString(i));
            }
            //第三行
            for (int i = 64; i >= 35; i--)
            {
                Console.Write(GetMapString(i));
            }
            Console.WriteLine();
            //第四行
            for (int i = 65; i <= 69; i++)
            {
                Console.WriteLine(GetMapString(i));
            }
            //第五行
            for (int i = 70; i <= 99; i++)
            {
                Console.Write(GetMapString(i));
            }

            //Console.WriteLine();
            //Console.ResetColor();

























        }


    }
}


  • 写回答

1条回答 默认 最新

  • threenewbee 2014-12-05 03:22
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序