| 这是一款初学者都能看懂代码的小游戏,只有不到30行代码。话不多说,上代码。 #include<bits/stdc++.h>
#include<windows.h>
#include<unistd.h>
#include<conio.h>
using namespace std;
int main(){
	int y=0,x=0;
	printf("请按w,a,s,d键控制小球移动\n");
	printf("请按空格键退出游戏\n");
	Sleep(1000);
	system("cls");
	printf("o\n");
	while(1){
		char s;
		s=getch();
		if(s==' ') break;
		if(s=='w') x--;
		if(s=='s') x++;
		if(s=='a') y--;
		if(s=='d') y++;
		if(y<0) y=0;
		if(x<0) x=0;
		system("cls");
		for(int i=1;i<=x;i++) cout<<endl;
		for(int i=1;i<=y;i++) cout<<' ';
		printf("o\n");
	}
	return 0;
}
 |