zoukankan      html  css  js  c++  java
  • 迷宫

    string[,] ditu = new string[8, 8]
    {
    {"■","人","■","■","■","■","■","■"},
    {"■"," ","■"," "," "," "," ","■"},
    {"■"," "," "," ","■","■"," ","■"},
    {"■","■","■","■"," "," "," ","■"},
    {"■"," "," "," "," ","■","■","■"},
    {"■"," ","■","■","■","■","■","■"},
    {"■"," "," "," "," "," "," "," "},
    {"■","■","■","■","■","■","■","■"},
    };


    int renx = 1;    
    int reny = 0;   //人的位置
    int mubiaox = 7;
    int mubiaoy = 6;  //目标点的位置
    while (true)
    {
    Console.Clear();
    for (int i = 0; i < 8; i++)
    {
    for (int j = 0; j < 8; j++)
    {
    Console.Write(ditu[i, j]);
    }
    Console.WriteLine("");
    }
    Console.WriteLine("请输入w上a左s下d右");
    string s = Console.ReadLine();
    int ydhx = 0;
    int ydhy = 0;
    if (s == "w" || s == "W")   //往上走一格
    {
    ydhx = renx;
    ydhy = reny - 1;
    }
    else if (s == "S" || s == "s")//往下走一格
    {
    ydhx = renx;
    ydhy = reny + 1;
    }
    else if (s == "A" || s == "a")//往左走一格
    {
    ydhx = renx - 1;
    ydhy = reny;
    }
    else if (s == "d" || s == "D")//往右走一格
    {
    ydhx = renx + 1;
    ydhy = reny;
    }
    else
    {
    Console.WriteLine("您输入有误");
    continue;
    }
    if (ditu[ydhy, ydhx] == "■")
    { }
    else if(ydhx==mubiaox&&ydhy==mubiaoy)
    {
    Console.WriteLine("恭喜走出迷宫");//到达目标点
    break;
    }

    else
    {
    ditu[reny, renx] = " ";
    renx = ydhx;
    reny = ydhy;
    ditu[reny, renx] = "人";//每走一格“人”变化
    }
    }
    Console.ReadLine();

  • 相关阅读:
    lvs_基础理论
    iptables_表和链(Traversing of tables and chains)
    题解-【集训队作业2018】Simple Tree
    题解-CF559C
    题解-[Violet]天使玩偶/SJY摆棋子
    题解-[POI2014]PRZ-Criminals
    题解-CF961G
    题解-CF1392H
    WorldCreator基础流程
    gstreamer-vaapi 之 README
  • 原文地址:https://www.cnblogs.com/jskbk/p/5354684.html
Copyright © 2011-2022 走看看