zoukankan      html  css  js  c++  java
  • 多维数组(推箱子地图及人运行)

      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("
    ");//换行
                  }
                  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操作后

  • 相关阅读:
    ATCoder code festival 2016 qual C
    2019.10.26模拟赛
    2019.10.24模拟赛
    狄利克雷卷积和莫比乌斯反演学习笔记
    ljq的互测の题解
    noi.ac #39
    noi.ac #741 code
    noi.ac #65 triangle
    让别人也可以访问你电脑上的ASP.NET MVC创建的网站
    ASP.NET MVC 开发中遇到的两个小问题
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4816738.html
Copyright © 2011-2022 走看看