自制飞机游戏ad控制左右
  • 板块灌水区
  • 楼主shenzhen01
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/10/13 11:16
  • 上次更新2024/10/13 11:20:15
查看原帖
自制飞机游戏ad控制左右
1497290
shenzhen01楼主2024/10/13 11:16
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
int p[2]={7,5},jg,m_s,l=1,r=4;
char mp[25][15],input;
void gotoxy(short x,short y){
	COORD pos = {x,y};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut, pos);
}
int rd(int x,int y){
	return rand()%(y-x+1)+x;
}void dp(int x,int y){
	mp[x][y] = '@';
	mp[x+1][y-1] = '@';
	mp[x+1][y] = '@';
	mp[x+1][y+1] = '@';
	mp[x+2][y] = '@';
	mp[x+3][y-1] = '@';
	mp[x+3][y+1] = '@';
}
void init(){
	for(int i=1;i<=20;i++){
		for(int j=1;j<=10;j++){
			mp[i][j] = ' ';
		}
	}
	for(int i=1;i<=20;i++){
		mp[i][1] = '#';
		mp[i][7] = '#';
		mp[i][8] = '#';
		mp[i][9] = '#';
		mp[i][10] = '#';
	}int a = p[0] = 17;
	int b = p[1] = 5;
	dp(a,b);
}bool lar(int w){
	for(int i=p[1]-1;i<=p[1]+1;i++){
		if(mp[p[0]-1][i]=='#')return false;
	}
	if(w==1){
		for(int i=p[0];i<=p[0]+3;i++){
			if(mp[i][p[1]-2]=='#')return false;
		}
	}else if(w==2){
		for(int i=p[0];i<=p[0]+3;i++){
			if(mp[i][p[1]+2]=='#')return false;
		}
	}return true;
}
void draw(){
	gotoxy(0,0);
	for(int i=1;i<=20;i++){
		for(int j=1;j<=10;j++){
			cout << mp[i][j] << " ";
		}cout << endl;
	} 
}void move(int way){
	for(int i=p[0];i<=p[0] + 3;i++){
		for(int j=p[1]-1;j<=p[1]+1;j++){
			mp[i][j] = ' ';
		}
	}
	if(way==1)p[1]--;
	else if(way==2)p[1]++;
	dp(p[0]-1,p[1]);
}void dd(){
	for(int i=20;i>=1;i--){
		for(int j=1;j<=10;j++){
			mp[i+1][j] = mp[i][j];
		}
	}if(jg==0){
		int z;
		do{
			z = rd(-2,2);
		}while(z==0 or l+z<1 or r-z<1);
		l+=z;
		r-=z;
		for(int i=1;i<=10;i++){
			mp[1][i] = ' ';
		}for(int i=1;i<=l;i++)mp[1][i] = '#';
		for(int i=10;i>=10-r+1;i--)mp[1][i] = '#';
		jg = rd(5,8);
	}else jg--;
}
int work(){
	float score = 0;
	init();
	draw();
	while(true){
		Sleep(200);
		input = ' ';
		while(kbhit())input = getch();
		if(input == 'a' and lar(1))move(1);
		else if(input == 'd' and lar(2))move(2);
		else if(input == 'h')input = getch();
		else if(input == 'e')break;
		else if(input !='a' and input !='d' and lar(0))move(0);
		else break;
		dd();
		draw();
		score+=0.4;
		cout << "当前分数"<<(int)(score)<<endl;
	}system("cls");
	return (int)(score);
}
int main(){
	srand(time(0));
	init();
	while(true){
		cout << "任意键开始,空格结束"<<endl;
		cout << "目前你的最高分是" << m_s << endl;
		input = getch();
		if(input!=' ')m_s = max(m_s,work());
		else break;
	}
	return 0;
}

2024/10/13 11:16
加载中...