zoukankan      html  css  js  c++  java
  • 练习!!迷宫

    static void Main(string[] args)
    {
    //数组:有固定长度的同种类型的一组变量,有索引,索引从0开始
    int[] shuzu = new int[5] { 2, 4, 5, 7, 9 };

    // Console.Write(shuzu[3]);


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

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

  • 相关阅读:
    VBS基础篇
    AcWing249 蒲公英(分块)
    CF1338B Edge Weight Assignment(思维+dfs)
    CF785E Anton and Permutation(分块)
    UCF Local Programming Contest 2015(Practice)D题
    AcWing851 spfa求最短路
    CF479E Riding in a Lift (dp)
    AcWing267 莫基亚(CDQ分治)
    P4093 [HEOI2016/TJOI2016]序列 (CDQ分治)
    2019ICPC南昌区域赛C题 And and Pair(数位dp)
  • 原文地址:https://www.cnblogs.com/lz123/p/4932182.html
Copyright © 2011-2022 走看看