码迷,mamicode.com
首页 > 编程语言 > 详细

多维数组(推箱子地图及人运行)

时间:2015-09-17 17:21:01      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

  string[,] erwei=new string[10,10]
            {
                {"","","","","","","","","",""},
                {"","  ","  ","  ","  ","","  ","  ","  ",""},
                {"","  ","","  ","  ","","  ","","  ",""},
                {"","  ","","","  ","","  ","  ","  ",""},
                {"","  ","  ","","  ","  ","  ","  ","  ",""},
                {"","  ","  ","","  ","  ","  ","","  ",""},
                {"","  ","","","  ","","  ","","  ",""},
                {"","  ","  ","  ","  ","","  ","  ","  ",""},
                {"","  ","","  ","","  ","  ","  ","  ",""},
                {"","","","","","","","","",""}
            };
          int reny = 1;
          int renx = 1;
          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 cuozuo = Console.ReadLine();
              if (cuozuo =="w") 
              {
                  if(erwei[reny-1,renx]=="  ")
                  {
                      reny =reny - 1;
                  }
              }
              if (cuozuo == "s")
              {
                  if (erwei[reny + 1, renx] == "  ")
                  {
                      reny = reny + 1;
                  }
              }
              if (cuozuo == "a")
              {
                  if (erwei[reny, renx-1] == "  ")
                  {
                      renx = renx - 1;
                  }
              }
              if (cuozuo == "d")
              {
                  if (erwei[reny, renx+1] == "  ")
                  {
                      renx = renx + 1;
                  }
              }
              erwei[reny, renx] = "";//输出人在多维数组中的新位置
              Console.Clear();//清除上一步痕迹
          }
          Console.ReadLine();
//初始位置
技术分享
//4步s操作后
技术分享

 

多维数组(推箱子地图及人运行)

标签:

原文地址:http://www.cnblogs.com/wang-kaifeng/p/4816738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!