首页 > 编程语言 > 详细

09.17,二维数组,地图

时间:2015-09-17 16:54:07      阅读:226      评论:0      收藏:0      [点我收藏+]

技术分享

  string[,] erwei = new string[10, 10] 
            {
                { "","","","","","","","","",""}, 
                { "","  ","  ","  ","  ","  ","","  ","  ",""}, 
                { "","  ","","","","  ","","","  ",""},
                { "","  ","","  ","","  ","  ","","  ",""},
                { "","  ","","  ","","","  ","","  ",""},
                { "","  ","","  ","  ","","","","  ",""},
                { "","  ","","  ","  ","  ","  ","  ","  ",""},
                { "","  ","  ","  ","","","","  ","",""},
                { "","  ","","  ","  ","","  ","  ","  ",""},
                { "","","","","","","","","","" } 
            };

            int reny = 4;
            int renx = 6;
            erwei[reny, renx] = "";

            while (true)
            {
               
                for (int j = 0; j < 10; j++)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Console.Write(erwei[j, i]);
                    }
                    Console.Write("\n");
                }

                erwei[reny, renx] = "  ";
                Console.Write("请按wasd来运动:");
                string caozuo = Console.ReadLine();
                if (caozuo == "w")
                {
                    if (erwei[reny - 1, renx] == "  ")
                    {
                        reny = reny - 1;
                    }
                }
                if (caozuo == "a")
                {
                    if (erwei[reny, renx - 1] == "  ")
                    {
                        renx = renx - 1;
                    }
                }
                if (caozuo == "s")
                {
                    if (erwei[reny + 1, renx] == "  ")
                    {
                        reny = reny + 1;
                    }
                }
                if (caozuo == "d")
                {
                    if (erwei[reny, renx + 1] == "  ")
                    {
                        renx = renx + 1;
                    }
                }

                erwei[reny, renx] = "";
                Console.Clear();
            }
            Console.ReadLine();

 

09.17,二维数组,地图

原文:http://www.cnblogs.com/cf924823/p/4816380.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!