《the Best Flying》

打飞机!
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
using namespace std;
char sky[16][11];
bool game;
int NumberOfEnemies;
int NumberOfShowing;
int score;
class player{
	public:
		int x=13;
		int y=5;
		char plane='A';
		char zd='|';
		bool attack=false;
		int x_zd;
		int y_zd;
};
class enemy{
	public:
		int x;
		int y;
		char plane='V';
};
player player1;
enemy enemies[11];
void color(int a){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void init(){
	int i,j;
	for(i=1;i<=15;i++)
		for(j=1;j<=10;j++)
			if(j==1||j==10)
				sky[i][j]='#';
			else sky[i][j]=' ';
	game=true;
	NumberOfEnemies=0;
	NumberOfShowing=0;
	score=0;
}
int RandomyOfEnemy(){
	srand(time(0));
	return rand()%8+2;
}
void show(){
	int i,j,k;
	bool ok;
	system("cls");
	for(i=1;i<=15;i++){
		for(j=1;j<=10;j++){
			ok=false;
			if(j>1&&j<10){
				if(game==false&&((i==player1.x&&(j==player1.y-1||j==player1.y+1))||(j==player1.y&&(i==player1.x-1||i==player1.x+1)))){
					color(14);
					cout<<"@";
					color(15);
					continue;
				}
				if(i==player1.x&&j==player1.y){
					if(game==true) color(11);
					else color(14);
					cout<<player1.plane;
					color(15);
					ok=true;
				}
				else{
					for(k=1;k<=NumberOfEnemies;k++)
						if(i==enemies[k].x&&j==enemies[k].y){
							if(enemies[k].plane=='@') color;
							else color(12);
							cout<<enemies[k].plane;
							color(15);
							ok=true;
							break;
						}
					if(ok==false&&player1.attack==true){
						if(i==player1.x_zd&&j==player1.y_zd){
							color(14);
							cout<<player1.zd;
							color(15);
							ok=true;
						}
					}
					if(ok==false) cout<<sky[i][j];
				}
			}
			else{
				color(10);
				cout<<sky[i][j];
				color(15);
				ok=true;
			}
		}
		cout<<endl;
	}
	cout<<"----------"<<endl;
	cout<<"Your score: "<<score;
}
void EnemiesMove(){
	int i;
	for(i=1;i<=NumberOfEnemies;i++)
		enemies[i].x++;
}
void NewEnemy(){
	int i;
	if(enemies[1].x>15){
		for(i=1;i<NumberOfEnemies;i++){
			enemies[i].x=enemies[i+1].x;
			enemies[i].y=enemies[i+1].y;
		}
		enemies[NumberOfEnemies].x=1;
		enemies[NumberOfEnemies].y=RandomyOfEnemy();
	}
}
void DieEnemy(){
	int i,j;
	bool ok=false;
	for(i=1;i<=NumberOfEnemies;i++){
		if((player1.x_zd==enemies[i].x||player1.x_zd==enemies[i].x+1||player1.x_zd==enemies[i].x-1)&&player1.y_zd==enemies[i].y){
			enemies[i].plane='@';
			show();
			Sleep(50);
			enemies[i].plane='V';
			for(j=i;j<NumberOfEnemies;j++){
				enemies[j].x=enemies[j+1].x;
				enemies[j].y=enemies[j+1].y;
			}
			enemies[NumberOfEnemies].x=1;
			enemies[NumberOfEnemies].y=RandomyOfEnemy();
			score++;
			ok=true;
		}
	}
	if(ok==true) player1.x_zd=0;
}
void DiePlayer(){
	int i;
	for(i=1;i<=NumberOfEnemies;i++){
		if(enemies[i].x==player1.x&&enemies[i].y==player1.y){
			game=false;
			player1.plane='@';
			break;
		}
	}
}
void ZdFly(){
	if(player1.attack==true)
		player1.x_zd-=2;
	if(player1.x_zd<1)
		player1.attack=false;
}
void PlayerAttack(){
	if(player1.attack==false&&player1.x>1){
		player1.attack=true;
		player1.x_zd=player1.x-1;
		player1.y_zd=player1.y;
	}
}
void PlayerDo(){
	while(kbhit()){
		switch(getch()){
			case 'w':
				if(player1.x>1)
					player1.x--;
			break;
			case 's':
				if(player1.x<15)
					player1.x++;
			break;
			case 'a':
				if(player1.y>2)
					player1.y--;
			break;
			case 'd':
				if(player1.y<9)
					player1.y++;
			break;
			case ' ':
				PlayerAttack();
			break;
		}
	}
}
void ProcedureOfGame(){
	init();
	cout<<"╔═══════════════╗"<<endl;
	cout<<"║       the Best Flying        ║"<<endl;
	cout<<"╠═══════════════╣"<<endl;
	cout<<"║  Made by Peter Winchester    ║"<<endl;
	cout<<"╠═══════════════╣"<<endl;
	cout<<"║         How to play          ║"<<endl;
	cout<<"║ Press w, s, a, d to move. The║"<<endl;
	cout<<"║A is your plane, and the V is ║"<<endl;
	cout<<"║enemies' plane. Press space to║"<<endl;
	cout<<"║attack enemies.               ║"<<endl;
	cout<<"║ How much score can you get?  ║"<<endl;
	cout<<"║ Press any key to start.      ║"<<endl;
	cout<<"╚═══════════════╝"<<endl;
	getch();
	while(game==true){
		NumberOfShowing++;
		if(NumberOfShowing<=10&&NumberOfEnemies<10&&NumberOfShowing%3==0){
			NumberOfEnemies++;
			enemies[NumberOfEnemies].x=1;
			enemies[NumberOfEnemies].y=RandomyOfEnemy();
		}
		show();
		Sleep(100);
		DieEnemy();
		EnemiesMove();
		DieEnemy();
		ZdFly();
		NewEnemy();
		PlayerDo();
		DiePlayer();
	}
	show();
	cout<<endl;
	cout<<"Game over!\n>>>Press m to quite.\n>>>";
}
void pause(char *a){
	do{
		*a=getch();
	}while(*a!='m');
	cout<<*a;
}
int main(){
	char a;
	ProcedureOfGame();
	pause(&a);
	return 0;
}
全部评论

相关推荐

伟大的烤冷面被普调:暨大✌🏻就是强
点赞 评论 收藏
分享
ProMonkey2024:5个oc?厉害! 但是有一个小问题:谁问你了?😡我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了(别的帖子偷来的,现学现卖😋)
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务