你能写出一个简易的音游C++代码嘛
时间: 2023-04-12 12:00:46 浏览: 104
当然可以,以下是一个简单的音游C代码:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
int main()
{
int x = SCREEN_WIDTH / 2;
int y = SCREEN_HEIGHT / 2;
int score = 0;
char input;
while (1) {
system("cls");
printf("Score: %d\n", score);
for (int i = 0; i < SCREEN_HEIGHT; i++) {
for (int j = 0; j < SCREEN_WIDTH; j++) {
if (i == y && j == x) {
printf("O");
} else {
printf(" ");
}
}
printf("\n");
}
if (_kbhit()) {
input = _getch();
if (input == 'a') {
x--;
} else if (input == 'd') {
x++;
} else if (input == 'w') {
y--;
} else if (input == 's') {
y++;
}
}
if (x < 0 || x >= SCREEN_WIDTH || y < 0 || y >= SCREEN_HEIGHT) {
printf("Game over!\n");
printf("Final score: %d\n", score);
break;
}
score++;
Sleep(50);
}
return 0;
}