09.17,二维数组,地图

  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();

 

posted @ 2015-09-17 14:44  小热包1  阅读(379)  评论(0编辑  收藏  举报