当前位置: 首页 > 工具软件 > kquery 2.0 > 使用案例 >

fighter(2.0)

周威
2023-12-01

fighter终于更新了,

这个游戏是我和蒟蒻尹一起编的,他写的和我差不多,

但是,我比他先进一些,

具体的,游戏中见

温馨提示

1.请先开好c++11,预防出错

2.最好开起声音(你玩就知道了)

CODE:

#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <conio.h>
#include "windows.h"
#pragma GCC optimize(3)
#pragma GCC optimize(2)
#define int long long
using namespace std;
const int row = 26+12;
const int col = 18*2;
struct Enemy {
	int x,y;
	int life;
} enemy[10000000];
int enemy_top=0;
struct Blast {
	int x,y;
	int making_tim;
	bool flag=0;
} blast[1000000];
int blast_top=0;
int tim_fire;
int tim_enemy_making;
bool v[row][col];
int p_fenshu=0;
int p_life=5;
int tot_gameshow,tot_realgame;
int Map[row][col] = {
//   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 0
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 1
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 3
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //31
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //32
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //33
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //34
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //35
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //36
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //37
};
int p_x=17,p_y=9;  //玩家的坐标  map[p_x][p_y];

void hide_cursor() {
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
	CursorInfo.bVisible = false; //隐藏控制台光标
	SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
inline int read() {
	char ch=getchar();
	int r=0,w=1;
	while(!isdigit(ch))w=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))r=(r<<3)+(r<<1)+(ch^48),ch=getchar();
	return r*w;
}
inline void write(int x) {
	char ch[100000];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	while(x)ch[len++]=(x%10)^48,x/=10;
	if(len==0)printf("0");
	while(len--)putchar(ch[len]);
}
void blast_making (int b_x,int b_y) {
	blast[++blast_top].making_tim=time(0);
	blast[blast_top].x=b_x;
	blast[blast_top].y=b_y;
	blast[blast_top].flag=1;
	Map[b_x][b_y]=10;
	Map[b_x+1][b_y]=11;
	Map[b_x-1][b_y]=11;
	Map[b_x][b_y+1]=11;
	Map[b_x][b_y-1]=11;
	Map[b_x+1][b_y+1]=12;
	Map[b_x+1][b_y-1]=12;
	Map[b_x-1][b_y+1]=12;
	Map[b_x-1][b_y-1]=12;
}
void blast_handle (int b_x,int b_y,int id) {
	int now_time=time(0);
	Map[b_x][b_y]=10;
	Map[b_x+1][b_y]=11;
	Map[b_x-1][b_y]=11;
	Map[b_x][b_y+1]=11;
	Map[b_x][b_y-1]=11;
	Map[b_x+1][b_y+1]=12;
	Map[b_x+1][b_y-1]=12;
	Map[b_x-1][b_y+1]=12;
	Map[b_x-1][b_y-1]=12;
	if(now_time-blast[id].making_tim>=1) {
		Map[b_x][b_y]=0;
		Map[b_x+1][b_y]=0;
		Map[b_x-1][b_y]=0;
		Map[b_x][b_y+1]=0;
		Map[b_x][b_y-1]=0;
		Map[b_x+1][b_y+1]=0;
		Map[b_x+1][b_y-1]=0;
		Map[b_x-1][b_y+1]=0;
		Map[b_x-1][b_y-1]=0;
		blast[id].flag=0;
	}
}
void blast_check () {
	for(int i=1; i<=blast_top; i++) {
		if(blast[i].flag==0) continue;
		blast_handle(blast[i].x,blast[i].y,i);
	}
}
void color (string ss) {
	if(ss=="RED")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
	if(ss=="BLU")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1);
	if(ss=="GRE")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
	if(ss=="YEL")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
	if(ss=="PUR")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
	if(ss=="GRA")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED);
	if(ss=="WHI")
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);

}

bool check(int x,int y) {
	if(x>=0&&y>=0&&x<=37&&y<=35) return true;
	return false;
}

void move(int x_mov,int y_mov) {  //玩家坐标位移
	p_x+=x_mov,p_y+=y_mov;
}

void fire(int p_x,int p_y) {
	int now_fire=time(0);
	if(tim_fire==0||now_fire-tim_fire>=1) {
		Map[p_x-1][p_y]=8;
		Map[p_x-1][p_y+1]=8;
		Map[p_x-2][p_y]=9;
		Map[p_x-2][p_y+1]=9;
		tim_fire=now_fire;
	}

}

void player_step() {  //位移操作
	Map[p_x][p_y]=0;
	Map[p_x][p_y+1]=0;
	Map[p_x+1][p_y+1]=0;
	Map[p_x+1][p_y]=0;
//	Map[p_x+1][p_y-1]=0;
	Map[p_x+1][p_y-2]=0;
//	Map[p_x+1][p_y+2]=0;
	Map[p_x+1][p_y+3]=0;
	Map[p_x+2][p_y+3]=0;
	Map[p_x+2][p_y+4]=0;
	Map[p_x+2][p_y+5]=0;
	Map[p_x+2][p_y+6]=0;
	Map[p_x+2][p_y+2]=0;
	Map[p_x+2][p_y+1]=0;
	Map[p_x+2][p_y]=0;
	Map[p_x+2][p_y-1]=0;
	Map[p_x+2][p_y-3]=0;
	Map[p_x+2][p_y-4]=0;
	Map[p_x+2][p_y-5]=0;
	Map[p_x+2][p_y-2]=0;
//	Map[p_x+3][p_y]=0;
//	Map[p_x+3][p_y+1]=0;
	Map[p_x+3][p_y+2]=0;
	Map[p_x+3][p_y-1]=0;
	Map[p_x+4][p_y]=0;
	Map[p_x+4][p_y+1]=0;
	Map[p_x+4][p_y-1]=0;
	Map[p_x+4][p_y+2]=0;
	Map[p_x+4][p_y+3]=0;
	Map[p_x+4][p_y+4]=0;
	Map[p_x+4][p_y-2]=0;
	Map[p_x+4][p_y-3]=0;
	if(GetKeyState(VK_UP) < 0&&p_x-1>=0) {
		move(-1, 0);
	}
	if(GetKeyState(VK_DOWN ) < 0&&p_x+1<=33) {
		move( 1, 0);
	}
	if(GetKeyState(VK_LEFT) < 0&&p_y-1>=5) {
		move( 0,-1);
	}
	if(GetKeyState(VK_RIGHT) < 0&&p_y+1<=29) {
		move( 0, 1);
	}
	if(GetKeyState(' ') < 0) {
		fire(p_x,p_y);
	}
	Map[p_x][p_y]=2;
	Map[p_x][p_y+1]=2;
	Map[p_x+1][p_y+1]=1;
	Map[p_x+1][p_y]=1;
//	Map[p_x+1][p_y-1]=7;
	Map[p_x+1][p_y-2]=1;
//	Map[p_x+1][p_y+2]=7;
	Map[p_x+1][p_y+3]=1;
	Map[p_x+2][p_y+3]=1;
	Map[p_x+2][p_y+4]=3;
	Map[p_x+2][p_y+5]=3;
	Map[p_x+2][p_y+6]=3;
	Map[p_x+2][p_y+2]=3;
	Map[p_x+2][p_y+1]=3;
	Map[p_x+2][p_y]=3;
	Map[p_x+2][p_y-1]=3;
	Map[p_x+2][p_y-3]=3;
	Map[p_x+2][p_y-4]=3;
	Map[p_x+2][p_y-5]=3;
	Map[p_x+2][p_y-2]=1;
//	Map[p_x+3][p_y]=7;
//	Map[p_x+3][p_y+1]=7;
	Map[p_x+3][p_y+2]=1;
	Map[p_x+3][p_y-1]=1;
	Map[p_x+4][p_y]=3;
	Map[p_x+4][p_y+1]=3;
	Map[p_x+4][p_y-1]=1;
	Map[p_x+4][p_y+2]=1;
	Map[p_x+4][p_y+3]=3;
	Map[p_x+4][p_y+4]=3;
	Map[p_x+4][p_y-2]=3;
	Map[p_x+4][p_y-3]=3;
}
//	puts("             ||		  ");
//	puts("           | || |       ");
//	puts("        ===|====|===    ");
//	puts("            |  |        ");
//	puts("          ==|==|==      ");
//	puts("");
//	puts("");
void enemy_clear(int e_x,int e_y) {
	if(v[e_x][e_y])Map[e_x][e_y]=0;
	if(v[e_x][e_y+1])Map[e_x][e_y+1]=0;
	if(v[e_x-1][e_y])Map[e_x-1][e_y]=0;
	if(v[e_x-2][e_y])Map[e_x-2][e_y]=0;
	if(v[e_x-3][e_y])Map[e_x-3][e_y]=0;
	if(v[e_x-1][e_y+1])Map[e_x-1][e_y+1]=0;
	if(v[e_x-2][e_y+1])Map[e_x-2][e_y+1]=0;
	if(v[e_x-3][e_y+1])Map[e_x-3][e_y+1]=0;
	if(v[e_x-1][e_y-1])Map[e_x-1][e_y-1]=0;
	if(v[e_x-2][e_y-3])Map[e_x-1][e_y-2]=0;
	if(v[e_x-1][e_y-3])Map[e_x-1][e_y-3]=0;
	if(v[e_x-1][e_y-4])Map[e_x-1][e_y-4]=0;
	if(v[e_x-1][e_y+2])Map[e_x-1][e_y+2]=0;
	if(v[e_x-1][e_y+3])Map[e_x-1][e_y+3]=0;
	if(v[e_x-1][e_y+4])Map[e_x-1][e_y+4]=0;
	if(v[e_x-1][e_y+5])Map[e_x-1][e_y+5]=0;
	if(v[e_x-3][e_y-1])Map[e_x-3][e_y-1]=0;
	if(v[e_x-3][e_y+2])Map[e_x-3][e_y+2]=0;
//	cout<<1<<" ";
}
void enemy_check(int e_x,int e_y,int id) {
	if(Map[e_x][e_y]==8||Map[e_x][e_y]==9) {
		enemy[id].life--;
		if(enemy[id].life==0) {
			Beep(50*1.25,1046);
			p_fenshu++;
			enemy_clear(enemy[id].x,enemy[id].y) ;
			blast_making(e_x,e_y);
			return ;
		}
	}
	if((check(e_x,e_y)&&Map[e_x][e_y]>=1&&Map[e_x][e_y]<=3)) {
		p_life-=1;
		p_fenshu++;
		enemy[id].life=0;
		enemy_clear(enemy[id].x,enemy[id].y) ;
		blast_making(e_x,e_y);
		return ;
	}
//	Map[e_x][e_y]=cor;
}



void enemy_move(int e_x,int e_y,int id) {
	enemy_clear(e_x,e_y);
	e_x+=1;
	enemy[id].x=e_x;
	if(v[e_x][e_y]) {
		enemy_check(e_x,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x][e_y]=4;
	}
	if(v[e_x][e_y+1]) {
		enemy_check(e_x,e_y+1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x][e_y+1]=4;
	}
	if(v[e_x-1][e_y]) {
		enemy_check(e_x-1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y]=6;
	}
	if(v[e_x-2][e_y]) {
		enemy_check(e_x-2,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-2][e_y]=6;
	}
	if(v[e_x-3][e_y]) {
		enemy_check(e_x-3,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-3][e_y]=6;
	}
	if(v[e_x-1][e_y+1]) {
		enemy_check(e_x-1,e_y+1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y+1]=6;
	}
	if(v[e_x-2][e_y+1]) {
		enemy_check(e_x-2,e_y+1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-2][e_y+1]=6;
	}
	if(v[e_x-3][e_y+1]) {
		enemy_check(e_x-3,e_y+1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-3][e_y+1]=6;
	}
	if(v[e_x-1][e_y-1]) {
		enemy_check(e_x-1,e_y-1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y-1]=7;
	}
	if(v[e_x-1][e_y-2]) {
		enemy_check(e_x-1,e_y-2,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y-2]=7;
	}
	if(v[e_x-1][e_y-3]) {
		enemy_check(e_x-1,e_y-3,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y-3]=7;
	}
	if(v[e_x-1][e_y-4]) {
		enemy_check(e_x-1,e_y-4,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y-4]=7;
	}
	if(v[e_x-1][e_y+2]) {
		enemy_check(e_x-1,e_y+2,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y+2]=7;
	}
	if(v[e_x-1][e_y+3]) {
		enemy_check(e_x-1,e_y+3,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y+3]=7;
	}
	if(v[e_x-1][e_y+4]) {
		enemy_check(e_x-1,e_y+4,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y+4]=7;
	}
	if(v[e_x-1][e_y+5]) {
		enemy_check(e_x-1,e_y+5,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-1][e_y+5]=7;
	}
	if(v[e_x-3][e_y-1]) {
		enemy_check(e_x-3,e_y-1,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-3][e_y-1]=7;
	}
	if(v[e_x-3][e_y+2]) {
		enemy_check(e_x-3,e_y+2,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
		Map[e_x-3][e_y+2]=7;
	}

	if(v[e_x+1][e_y]) {

		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x+1][e_y+1]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y+2]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y+3]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y+4]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y+5]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y-1]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y-2]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y-3]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}
	if(v[e_x][e_y-4]) {
		enemy_check(e_x+1,e_y,id);
		if(enemy[id].life==false) {
			enemy_clear(e_x,e_y);
			return ;
		}
	}


}
void enemy_step() {
	for(int i=1; i<=enemy_top; i++) {
		if(!enemy[i].life) continue;
		enemy_move(enemy[i].x,enemy[i].y,i);
	}
}

void enemy_make() {
	int now_tim_enemy=time(0);
	srand(time(0));
	int enemy_making_lie=rand()%26+4;
	if(now_tim_enemy-tim_enemy_making>=2) {
		enemy[++enemy_top].life=1;
		enemy[enemy_top].x=1;
		enemy[enemy_top].y=enemy_making_lie;
		tim_enemy_making=now_tim_enemy;
	}
}
//    =||=
//     ||
// ====||====
//	   --
void draw(int x,int y) {
	if(Map[x][y]==0) putchar (' ');
//  1~3:player
	if(Map[x][y]==1||Map[x][y]==2) color("GRE"),putchar('|');
	if(Map[x][y]==3)               color("GRE"),putchar('=');
//  4~7:enemy
	if(Map[x][y]==4||Map[x][y]==5) color("GRA"),putchar('-');
	if(Map[x][y]==6)               color("GRA"),putchar('|');
	if(Map[x][y]==7)               color("GRA"),putchar('=');
//  8~9:bullet
	if(Map[x][y]==8) { //子弹特殊操作
		color("YEL"),putchar('^');
		Map[x][y]=0;
		if(x-1)
			Map[x-1][y]=8;
	}
	if(Map[x][y]==9) { //子弹特殊操作
		color("YEL"),putchar(' ');
		Map[x][y]=0;
		if(x-1)
			Map[x-1][y]=9;
	}
//  10~12:blast
	if(Map[x][y]==10)               color("YEL"),putchar('O');
	if(Map[x][y]==11)               color("RED"),putchar('o');
	if(Map[x][y]==12)               color("WHI"),putchar('+');
}
void home();
void game();
void teach();
void team();
void home () {
	system("mode con cols=62 lines=41");
	p_life=5;
	p_fenshu=0;
	color("YEL");
	int n;
	cout<<"      _____          _______         ____        _____"<<endl;
	cout<<"     /____/|        /______/\\       /___/|      /____/|"<<endl;
	cout<<"    /_   | |       /  ___  \\/|     /   | |     /_   | |"<<endl;
	cout<<"      |  | |       | /\\__\\ | |    / /| | |_      |  | |"<<endl;
	cout<<"      |  | |       | \\/__/ | |   / /_| |/_/|     |  | |"<<endl;
	cout<<"      |  | |       \\____   | |   |___   __|/     |  | |"<<endl;
	cout<<"     _|  | |__      ____|  | |       | | |      _|  | |__"<<endl;
	cout<<"    /_|  |/__/|    /____|  |/        | | |     /_|  |/__/|"<<endl;
	cout<<"    |________|/    \\_______/         |_|/      |________|/"<<endl;
	cout<<endl<<endl;
	color("WHI");
	cout<<"                       1.开始游戏 "<<endl;
	cout<<"                       2.游戏教程 "<<endl;
	cout<<"                       3.制作团队 "<<endl;
	cout<<"                       4.推出游戏 "<<endl;
	cout<<"                       请选择: ";
	n=read();
	if(n==1) {
		game();
	}
	if(n==2) {
		teach();
	}
	if(n==3) {
		team();
	}
	if(n==4) {
		system("cls");
		cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
		exit(0);
	}
}
void team() {
	system("mode con cols=62 lines=41");
	color("WHI");
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	cout<<"                   作者: $蒟蒻尹$ 、xiedongbiao     \n     "<<endl;
	cout<<"                   策划:蒟蒻尹          \n"<<endl;
	cout<<"                   测试:xiedongbiao          \n"<<endl;
	cout<<"                   美术:蒟蒻尹          \n"<<endl;
	cout<<"                   校正:xiedongbiao          \n"<<endl;
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	system("pause");
	system("cls");
	home();
}
void teach() {
	system("mode con cols=62 lines=41");
	color("WHI");
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	cout<<"                  ↑           "<<endl;
	cout<<"             按 ←↓→控制飞机移动, 按 \"空格\" 键开火          "<<endl;
	cout<<"                       此游戏有防沉迷功能,请注意安全           "<<endl;
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	system("pause");
	system("cls");
	home();
}
void die() {
	color("WHI");
	system("mode con cols=62 lines=41");
	int n;
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	cout<<"                       1.返回主页 "<<endl;
	cout<<"                       2.退出游戏 "<<endl;
	cout<<"                       请选择: ";
	n=read();
	if(n==1) {
		home();
	}
	if(n==2) {
		system("cls");
		cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
		exit(0);
	}
}
void game() {

	hide_cursor();
	for(int i=0; i<=37; i++) {
		for(int j=0; j<=35; j++) {
			v[i][j]=1;
			Map[i][j]=0;
		}
	}
	system("mode con cols=37 lines=41");
	while (true) {
		tot_gameshow++;
		if(tot_gameshow==2) tot_gameshow=1,tot_realgame++,tot_realgame%=100;
		if(p_life==0) die();
		enemy_make();
		enemy_step();
		player_step();
		blast_check();
		color("WHI");
		printf("     SCORE             LIFE\n");
		color("YEL");
		printf("       %d               " ,p_fenshu);
		color("RED");
		for(int i=1; i<=p_life; i++) cout<<(char)3;
		printf("\n");
		color("WHI");
		for(int i=1; i<=35; i++) printf("-");
		printf("\n");
		for(int i=0; i<=37; i++) {
			for(int j=0; j<=35; j++) {
				draw(i,j);
			}
			if(i!=row-1)puts("");
		}
		Sleep(abs(100-tot_realgame));
		system("cls");
	}
}
signed main() {
	home();
	return 0;
}

 类似资料: