#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<windows.h>
char a[20][20] =
{
"*****************",
"*0****....**.....",
"*.****.**.**.****",
"*......**.**.****",
"*.*******....****",
"*.*...*.****.****",
"*.*.*.*.****.****",
"*.*.*........****",
"*...***..********",
"*****************",
};
using namespace std;
void welcome() {
printf("\n\n 吃豆豆");
printf("\n\n 请按任意键开始,wasd控制");
_getch();
system("cls");
}
void hide() {
HANDLE hOut;
CONSOLE_CURSOR_INFO curInfo;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
curInfo.dwSize = 1;
curInfo.bVisible = 0;
SetConsoleCursorInfo(hOut, &curInfo);
}
void set() {
HANDLE hOut;
COORD pos = { 0,0 };//设置光标初始位置
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
int main() {
hide();
int flag = 0;
welcome();
int x, y;
x = 1; y = 1;
char ch;
for (int i = 0; i < 10; i++)
puts(a[i]);
while (1) {
ch = _getch();
if (ch == 's') {
if (a[x + 1][y] == ' ')
{
a[x][y] = ' ';
x++;
a[x][y] = '0';
}
else if (a[x + 1][y] == '.')
{
a[x][y] = ' ';
x++;
a[x][y] = '0';
flag++;
}
}
else if (ch == 'w') {
if (a[x - 1][y] == ' ')
{
a[x][y] = ' ';
x--;
a[x][y] = '0';
}
else if (a[x - 1][y] == '.')
{
a[x][y] = ' ';
x--;
a[x][y] = '0';
flag++;
}
}
else if (ch == 'a') {
if (a[x][y - 1] == ' ')
{
a[x][y] = ' ';
y--;
a[x][y] = '0';
}
else if (a[x][y - 1] == '.')
{
a[x][y] = ' ';
y--;
a[x][y] = '0';
flag++;
}
}
else if (ch == 'd') {
if (a[x][y + 1] == ' ')
{
a[x][y] = ' ';
y++;
a[x][y] = '0';
}
else if (a[x][y + 1] == '.')
{
a[x][y] = ' ';
y++;
a[x][y] = '0';
flag++;
}
}
set();
for (int i = 0; i < 10; i++)
puts(a[i]);
cout << "法力值:" << flag << endl;
cout << endl;
if (x == 8 && y == 7)
{cout << "触发神秘机关,掉落一本法典,啪嗒你被知识击中了" << endl;
cout << "you failed!" << endl;
Sleep(2000);
system("pause"); break;
}
if (x == 5 && y == 7)
{
cout << "触发神秘机关,从天上掉落一本法典,啪嗒你被知识击中了" << endl;
cout << "you failed!" << endl;
Sleep(2000);
system("pause");
break;
}
if (flag == 50) {
cout << "Congratulatitions!难道您就是大法官!!!" << endl;
Sleep(2000);
system("pause"); break;
}
}
return 0;
}
简易吃豆人
于 2023-01-03 18:43:59 首次发布