A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ↖落葉下♀媃媚 中级黑马   /  2013-3-29 21:17  /  1173 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 ↖落葉下♀媃媚 于 2013-3-30 10:21 编辑

static int[] Map = new int[100];
        static int[] playerpos = { 0, 0 };//表示AB的坐标

        static void Main(string[] args)
        {
            string[] names = new string[2];//定义一个数组存放玩家的名字
            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[0] == names[1])
            {
                if (names[1] == "")
                {
                    Console.WriteLine("玩家B的姓名不能为空,请重新输入?");
                    names[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("该玩家名已存在,请重新输入?");
                    names[1] = Console.ReadLine();
                }

            }
            Console.Clear();
            ShowUI();
            Console.WriteLine("对战开始。。。。");
            Console.WriteLine("玩家{0}用A表示", names[0]);
            Console.WriteLine("玩家{0}用B表示", names[1]);
            Console.WriteLine("如果AB在同一位置用〈〉表示");
            
            Initiamap();
            drawmap();
            Console.ReadKey();
        }
        #region  显示游戏开始时的界面 + static void ShowUI()
        static void ShowUI()
        {
            Console.WriteLine("************************************");
            Console.WriteLine("*                                  *");
            Console.WriteLine("* 骑   士   飞   行   棋           *");
            Console.WriteLine("*                                  *");
            Console.WriteLine("************************************");
        }
        #endregion
        #region 初始化地图数组+ static void Initiamap()
        static void Initiamap()
        {

            int[] luckTurn = { 6, 23, 40, 55, 69, 83, 98 };//幸运轮盘 1◎
            int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷 2 ★
            int[] pause = { 9, 27, 60, 93 };//暂停 3  △
            int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道 4卐
            for (int i = 0; i < luckTurn.Length; i++)
            {

                Map[luckTurn] =1 ;
            }
            for (int i = 0; i < landMine.Length; i++)
            {
                Map[landMine] =2;
            }

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

                Map[timeTunnel] =4;
            }
        }
        #endregion
        #region 画地图+static void drawmap()
        static void drawmap()
        {//画第一行
            
            for (int i = 0; i <= 29; i++)
            {
               
                if (playerpos[0] == playerpos[1])
                {
                    Console.Write("<>");
                }
                else if (playerpos[0] == i)//A在当前格上
                {
                    Console.Write("A");
                }
                else if (playerpos[1] == i)//判断B在当前格上
                {
                    Console.Write("B");
                }
                else
                {
                 switch(Map)
                 {
                 case0:
                    Console.WriteLine("");
                    break;
                 case1:
                    Console.WriteLine("");

                    break;
                 }
                }
            }
        #endregion
        }
   
}
后边这两个case只要输入就出错,为什么?

评分

参与人数 1技术分 +1 收起 理由
苏波 + 1

查看全部评分

3 个回复

倒序浏览
case 0:
       Console.WriteLine("");
       break;
case 1:
       Console.WriteLine("");
case和0、1之间加一个空格就好了,像我上面那样就行了

评分

参与人数 1技术分 +1 收起 理由
苏波 + 1

查看全部评分

回复 使用道具 举报

Map是int[]类型的吧
回复 使用道具 举报
胡志超 发表于 2013-3-29 21:22
case 0:
       Console.WriteLine("");
       break;

谢谢,已解决
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马