您的位置:首页 > 其它

迷宫移动

2015-09-17 20:24 375 查看
string[,] erwei = new string[12, 11]
{
{"■","■","■","■","■","■","■","■","■","  ","■"},
{"■","  ","  ","  ","  ","  ","  ","  ","  ","  ","■"},
{"■","  ","  ","■","■","  ","  ","  ","  ","  ","■"},
{"■","  ","■","  ","  ","■","  ","  ","  ","  ","■"},
{"■","  ","■","  ","  ","  ","■","  ","  ","  ","■"},
{"■","  ","■","  ","  ","  ","■","  ","  ","  ","■"},
{"■","  ","■","  ","■","  ","■","  ","  ","  ","■"},
{"■","  ","■","  ","■","  ","■","  ","  ","  ","■"},
{"■","  ","■","  ","■","  ","■","  ","  ","■","■"},
{"■","  ","■","  ","■","  ","  ","■","■","  ","■"},
{"■","  ","  ","  ","■","  ","  ","  ","  ","  ","■"},
{"■","■","■","■","■","■","■","■","■","■","■"}
};

int reny = 9;
int renx = 9;
erwei[reny, renx] = "人";

while (true)
{
for (int j = 0; j < 12; j++)
{
for (int i = 0; i < 11; i++)
{
Console.Write(erwei[j, i]);
}
Console.Write("\n");
}

erwei[reny, renx] = "  ";
Console.Write("请输入:");
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();
if (reny == 0 && renx == 9)
{
Console.Write("游戏结束,已逃脱!");
break;
}

}
Console.ReadLine();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: