极为简单滴迷宫游戏c++
Posted 道标 · 落彡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了极为简单滴迷宫游戏c++相关的知识,希望对你有一定的参考价值。
不想写注释
代码:
#include <iostream>
using namespace std;
int main()
{
cout << "wsad = 上下左右" << endl;
char a[10][10] =
{
{'#','#','#','#','#','#','#','#','#','#'},
{'#',' ',' ','#','#',' ','#','#',' ',' '},
{'#',' ','#',' ',' ',' ',' ','#',' ','#'},
{'#',' ',' ',' ','#','#',' ','#',' ','#'},
{'#','O',' ','#','#',' ',' ','#',' ','#'},
{'#',' ','#',' ',' ','#',' ',' ',' ','#'},
{'#',' ','#',' ',' ','#',' ','#',' ','#'},
{'#',' ',' ','#','#',' ',' ',' ',' ','#'},
{'#','#',' ',' ',' ',' ','#','#',' ','#'},
{'#','#','#','#','#','#','#','#','#','#'},
};
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
char ch;
int x = 4, y = 1;
int q = 1, p = 9;
while(cin >> ch)
{
system("cls");
if(ch == 'w' && a[x - 1][y] != '#')
{
a[x][y] = ' ';
x--;
a[x][y] = 'O';
}
else if(ch == 's' && a[x + 1][y] != '#')
{
a[x][y] = ' ';
x++;
a[x][y] = 'O';
}
else if(ch == 'a' && a[x][y - 1] != '#')
{
a[x][y] = ' ';
y--;
a[x][y] = 'O';
}
else if(ch == 'd' && a[x][y + 1] != '#')
{
a[x][y] = ' ';
y++;
a[x][y] = 'O';
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
if(x == q && y == p)
{
cout << "win";
break;
}
}
return 0;
}
以上是关于极为简单滴迷宫游戏c++的主要内容,如果未能解决你的问题,请参考以下文章