0
已解决
陶欣怡
资深守护
资深守护
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int x = 0, y = 0, vx = 1, vy = 0, score = 0;
int a = 0, d = 0, w = 0, s = 0;
char ch;
while (y <= 24) {
if (_kbhit()) {
ch = _getch();
switch (ch) {
case 'a':
a = 1;
break;
case 'd':
d = 1;
break;
case 'w':
w = 1;
break;
case 's':
s = 1;
break;
default:
break;
}
}
y++;
if (y == 5 || y == 10 || y == 15 || y == 20) {
score += y * 10;
}
if (a == 1) {
x -= vx;
a = 0;
}
if (d == 1) {
x += vx;
d = 0;
}
if (w == 1) {
vy -= 1;
w = 0;
}
if (s == 1) {
vy += 1;
s = 0;
}
if (x <= -5) {
x = -5;
}
if (x >= 5) {
x = 5;
}
if (vy >= 10) {
vy = 10;
}
if (vy <= -10) {
vy = -10;
}
system("cls");
cout << "Score: " << score << endl;
cout << "Player Position: (" << x << ", " << y << ")" << endl;
cout << "Move: ";
if (a == 0 && d == 0 && w == 0 && s == 0) {
cout << "None" << endl;
} else {
if (a == 1) {
cout << "Left" << endl;
} else if (d == 1) {
cout << "Right" << endl;
} else if (w == 1) {
cout << "Jump" << endl;
} else if (s == 1) {
cout << "Crouch" << endl;
} else {
cout << "None" << endl;
}
}
Sleep(100);
}
return 0;
}
运行错误QAQ