c++ 炸弹人

注意不要站在炸弹上,会承受四倍伤害
玩家一 ↑ ↓←→ 控制移动 [回车] 放炸弹
玩家二 w s a d 控制移动 [空格] 放炸弹
∷ 增加炸弹数量
▓ 增加炸弹威力
※ 减短炸弹引线
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>

const int M = 1e3 + 5;
int wall[15][15] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1},{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1},{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1},{0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1},{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1},{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},{0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1},{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
int block[15][15] = {{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, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0},{0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
int thing[M][M];
int num, start;

void stop() {
	while(true) {
		system("pause");
	}
}

struct player{
	int x, y;
	int bown;
	int nom_bown;
	int time;
	int life;
	int fire;
}a[M];

struct bown{
	int x, y;
	int time;
	int from;
}b[M];

bool bow(int x, int y) {
	for(int i = start; i <= num && num != 0; i ++) {
		if(b[i].x == x && b[i].y == y) return true;
	}
	return false;
}

int main() {
	srand((unsigned)time(0));
	a[1].life = 20;
	a[2].life = 20;
	a[1].fire = 1;
	a[2].fire = 1;
	a[1].bown = 1;
	a[2].bown = 1;
	a[1].x = 13;
	a[1].y = 2;
	a[2].x = 2;
	a[2].y = 13;
	a[1].time = 2000;
	a[2].time = 2000;
	while(a[1].life > 0 && a[2].life > 0) {
		for(int i = 1; i <= 14; i ++) {
			for(int j = 1; j <= 14; j ++) {
				if(wall[i][j] == 1) printf("■");
				else if(block[i][j] == 1) printf("☆");
				else if(a[1].x == i && a[1].y == j) printf("①");
				else if(a[2].x == i && a[2].y == j) printf("②");
				else if(bow(i, j)) printf("●");
				else if(thing[i][j] == 1) printf("∷");
				else if(thing[i][j] == 2) printf("▓");
				else if(thing[i][j] == 3) printf("※");
				else if(thing[i][j] == 4) printf("◆");
				else printf("  ");
			}
			puts("");
		}
		printf("玩家一 生命值 %d  %d● %d级炸弹 爆炸时间 %dms\n", a[1].life, a[1].bown - a[1].nom_bown, a[1].fire, a[1].time);
		printf("玩家二 生命值 %d  %d● %d级炸弹 爆炸时间 %dms\n", a[2].life, a[2].bown - a[2].nom_bown, a[2].fire, a[2].time);
		if(kbhit()){
			char c = getch();
			if(c == -32) {
				c = getch();
				if(c == 72 && block[a[1].x - 1][a[1].y] == 0 && wall[a[1].x - 1][a[1].y] == 0 && bow(a[1].x - 1, a[1].y) == false) {
					-- a[1].x;
				}
				if(c == 80 && block[a[1].x + 1][a[1].y] == 0 && wall[a[1].x + 1][a[1].y] == 0 && bow(a[1].x + 1, a[1].y) == false) {
					++ a[1].x;
				}
				if(c == 75 && block[a[1].x][a[1].y - 1] == 0 && wall[a[1].x][a[1].y - 1] == 0 && bow(a[1].x, a[1].y - 1) == false) {
					-- a[1].y;
				}
				if(c == 77 && block[a[1].x][a[1].y + 1] == 0 && wall[a[1].x][a[1].y + 1] == 0 && bow(a[1].x, a[1].y + 1) == false) {
					++ a[1].y;
				}
			}
			if(c == 'w' && block[a[2].x - 1][a[2].y] == 0 && wall[a[2].x - 1][a[2].y] == 0 && bow(a[2].x - 1, a[2].y) == false) {
				-- a[2].x;
			}
			if(c == 's' && block[a[2].x + 1][a[2].y] == 0 && wall[a[2].x + 1][a[2].y] == 0 && bow(a[2].x, a[2].y + 1) == false) {
				++ a[2].x;
			}
			if(c == 'a' && block[a[2].x][a[2].y - 1] == 0 && wall[a[2].x][a[2].y - 1] == 0 && bow(a[2].x, a[2].y - 1) == false) {
				-- a[2].y;
			}
			if(c == 'd' && block[a[2].x][a[2].y + 1] == 0 && wall[a[2].x][a[2].y + 1] == 0 && bow(a[2].x, a[2].y + 1) == false) {
				++ a[2].y;
			}
			if(c == 13 && a[1].nom_bown < a[1].bown) {
				++ num;
				b[num].x = a[1].x;
				b[num].y = a[1].y;
				b[num].time = clock() + a[1].time;
				b[num].from = 1;
				++ a[1].nom_bown;
			}
			if(c == ' ' && a[2].nom_bown < a[2].bown) {
				++ num;
				b[num].x = a[2].x;
				b[num].y = a[2].y;
				b[num].time = clock() + a[2].time;
				b[num].from = 2;
				++ a[2].nom_bown;
			}
		}
		for(int i = start; i <= num; i ++) {
			if(clock() >= b[i].time) {
				++ start;
				-- a[b[i].from].nom_bown;
				for(int j = b[i].x; j <= b[i].x + a[b[i].from].fire; j ++){
					thing[j][b[i].y] = 0;
					if(wall[j][b[i].y] == true) break;
					if(block[j][b[i].y] == true) {
						block[j][b[i].y] = false;
						thing[j][b[i].y] = rand() % 5;
						break;
					}
					if(a[1].x == j && a[1].y == b[i].y) a[1].life -= a[b[i].from].fire;
					if(a[2].x == j && a[2].y == b[i].y) a[2].life -= a[b[i].from].fire;
				}
				for(int j = b[i].x; j >= b[i].x - a[b[i].from].fire; j --){
					thing[j][b[i].y] = 0;
					if(wall[j][b[i].y] == true) break;
					if(block[j][b[i].y] == true) {
						block[j][b[i].y] = false;
						thing[j][b[i].y] = rand() % 5;
						break;
					}
					if(a[1].x == j && a[1].y == b[i].y) a[1].life -= a[b[i].from].fire;
					if(a[2].x == j && a[2].y == b[i].y) a[2].life -= a[b[i].from].fire;
				}
				for(int j = b[i].y; j <= b[i].y + a[b[i].from].fire; j ++){
					thing[b[i].x][j] = 0;
					if(wall[b[i].x][j] == true) break;
					if(block[b[i].x][j] == true) {
						block[b[i].x][j] = false;
						thing[b[i].x][j] = rand() % 5;
						break;
					}
					if(a[1].x == b[i].x && a[1].y == j) a[1].life -= a[b[i].from].fire;
					if(a[2].x == b[i].x && a[2].y == j) a[2].life -= a[b[i].from].fire;
				}
				for(int j = b[i].y; j >= b[i].y - a[b[i].from].fire; j --){
					thing[b[i].x][j] = 0;
					if(wall[b[i].x][j] == true) break;
					if(block[b[i].x][j] == true) {
						block[b[i].x][j] = false;
						thing[b[i].x][j] = rand() % 5;
						break;
					}
					if(a[1].x == b[i].x && a[1].y == j) a[1].life -= a[b[i].from].fire;
					if(a[2].x == b[i].x && a[2].y == j) a[2].life -= a[b[i].from].fire;
				}
			}
		}
		if(thing[a[1].x][a[1].y] == 1) {
			thing[a[1].x][a[1].y] = 0;
			++ a[1].bown;
		}
		if(thing[a[1].x][a[1].y] == 2) {
			thing[a[1].x][a[1].y] = 0;
			++ a[1].fire;
		}
		if(thing[a[2].x][a[2].y] == 1) {
			thing[a[2].x][a[2].y] = 0;
			++ a[2].bown;
		}
		if(thing[a[2].x][a[2].y] == 2) {
			thing[a[2].x][a[2].y] = 0;
			++ a[2].fire;
		}
		if(thing[a[1].x][a[1].y] == 3) {
			thing[a[1].x][a[1].y] = 0;
			a[1].time -= a[1].time >= 500 ? 150 : 0;
		}
		if(thing[a[2].x][a[2].y] == 3) {
			thing[a[2].x][a[2].y] = 0;
			a[2].time -= a[2].time >= 500 ? 150 : 0;
		}
		if(thing[a[1].x][a[1].y] == 4) {
			thing[a[1].x][a[1].y] = 0;
			a[1].life += 5;
		}
		if(thing[a[2].x][a[2].y] == 4) {
			thing[a[2].x][a[2].y] = 0;
			a[2].life += 5;
		}
		Sleep(5);
		system("cls");
	}
	if((a[1].life || a[2].life ) == 0) {
		printf("一虎杀两羊\n");
		stop();
		return 0; 
	}
	if(a[1].life > 0) {
		printf("二号在轰的一声巨响中消失了\n");
		stop();
		return 0;
	}
	printf("一号已升天\n"); 
	stop();
	return 0;
}

上一篇:PHP 核心特性 - Trait(Life)


下一篇:A Bug's Life(带权并查集)POJ - 2492