zoukankan      html  css  js  c++  java
  • 迷宫移动

     1 string[,] erwei = new string[12, 11] 
     2             {
     3                 {"","","","","","","","","","  ",""}, 
     4                 {"","  ","  ","  ","  ","  ","  ","  ","  ","  ",""}, 
     5                 {"","  ","  ","","","  ","  ","  ","  ","  ",""},
     6                 {"","  ","","  ","  ","","  ","  ","  ","  ",""},
     7                 {"","  ","","  ","  ","  ","","  ","  ","  ",""},
     8                 {"","  ","","  ","  ","  ","","  ","  ","  ",""},
     9                 {"","  ","","  ","","  ","","  ","  ","  ",""},
    10                 {"","  ","","  ","","  ","","  ","  ","  ",""},
    11                 {"","  ","","  ","","  ","","  ","  ","",""},
    12                 {"","  ","","  ","","  ","  ","","","  ",""},
    13                 {"","  ","  ","  ","","  ","  ","  ","  ","  ",""},
    14                 {"","","","","","","","","","",""} 
    15             };
    16 
    17             int reny = 9;
    18             int renx = 9;
    19             erwei[reny, renx] = "";
    20 
    21             while (true)
    22             {
    23                 for (int j = 0; j < 12; j++)
    24                 {
    25                     for (int i = 0; i < 11; i++)
    26                     {
    27                         Console.Write(erwei[j, i]);
    28                     }
    29                     Console.Write("
    ");
    30                 }
    31 
    32                 erwei[reny, renx] = "  ";
    33                 Console.Write("请输入:");
    34                 string caozuo = Console.ReadLine();
    35                 if (caozuo == "w")
    36                 {
    37                     if (erwei[reny - 1, renx] == "  ")
    38                     {
    39                         reny = reny - 1;
    40                     }
    41                 }
    42                 if (caozuo == "a")
    43                 {
    44                     if (erwei[reny, renx - 1] == "  ")
    45                     {
    46                         renx = renx - 1;
    47                     }
    48                 }
    49                 if (caozuo == "s")
    50                 {
    51                     if (erwei[reny + 1, renx] == "  ")
    52                     {
    53                         reny = reny + 1;
    54                     }
    55                 }
    56                 if (caozuo == "d")
    57                 {
    58                     if (erwei[reny, renx + 1] == "  ")
    59                     {
    60                         renx = renx + 1;
    61                     }
    62                 }
    63                
    64                 erwei[reny, renx] = "";
    65                 Console.Clear();
    66                 if (reny == 0 && renx == 9)
    67                 {
    68                     Console.Write("游戏结束,已逃脱!");
    69                     break;
    70                 }
    71                     
    72 
    73               
    74             }
    75             Console.ReadLine();
  • 相关阅读:
    0 MATLAB的基本语法测试(7.20)
    eclipse(java)安装swing designer
    Request的用法
    requests模拟登陆的三种方式
    requests模块使用代理
    利用Python爬取翻译网站的翻译功能
    request发送带headers和带参数的请求
    爬虫的介绍和概念
    ROBOTS协议
    爬虫的流程
  • 原文地址:https://www.cnblogs.com/name-hanlin/p/4817560.html
Copyright © 2011-2022 走看看