不多说,直接上代码:(后期会更新哦)
#include<bits/stdc++.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
char s[200][200],c;
int x = 1,y = 1,cnt,a = -1,b;
void make()
{
srand((unsigned)time(0));
while(a == -1)
{
a = rand() % 20 + 1,b = rand() % 50 + 1;
if (a == x && b == y)
a = -1;
}
s[a][b] = '$';
}
int main()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
for (int i = 1; i <= 20; i++)
for (int j = 1; j <= 50; j++)
s[i][j] = ' ';
s[1][1] = 'Y';
while(1)
{
make();
cout << ' ';
for (int j = 1; j <= 50; j++)
cout << "—";
cout << "\n";
for (int i = 1; i <= 20; i++)
{
cout << '|';
for (int j = 1; j <= 50; j++)
cout << s[i][j];
cout << "|\n";
}
cout << ' ';
for (int j = 1; j <= 50; j++)
cout << "—";
cout << "\n";
cout << "You get:" << cnt;
Sleep(80);
system("cls");
if (KEY_DOWN('W'))
s[x][y] = ' ',s[--x][y] = 'Y';
if (KEY_DOWN('A'))
s[x][y] = ' ',s[x][--y] = 'Y';
if (KEY_DOWN('D'))
s[x][y] = ' ',s[x][++y] = 'Y';
if (KEY_DOWN('S'))
s[x][y] = ' ',s[++x][y] = 'Y';
if (x == a && y == b)
cnt++,a = -1;
if (x < 1 || y < 1 || x > 20 || y > 50)
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n YOU DIE!";
Sleep(2000);
exit(0);
}
}
return 0;
}