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


      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操作后

  • 相关阅读:
    core文件生成总结
    php 5.2 版本isset()方法小坑
    gdb调试memcached
    mysql的sql优化案例
    php对mongo操作问题
    memcache锁
    php的session实现
    linux指令tips
    php拦截器(魔术方法)
    Nginx源码研究八:nginx监听socket实现流程
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4816738.html
Copyright © 2020-2023  润新知