终于,经历了千辛万苦,我终于写出了人机(一个ZZ,能把自己闷在炸弹堆里)…
这个代码打得有些仓促,有问题请在评论区留言。
经典模式(1.0)
C o d e Code Code
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <queue>
#include <utility>
using namespace std;
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;
int last;
int wa[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 bl[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}};
void stop() {
for (int i = 2; i <= 5; i ++) {
system("pause");
}
}
void put(char *p) {
while(1) {
if(*p != 0)
printf("%c", *p ++);
else
break;
Sleep(20);
}
}
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;
}
void put_map() {
system("cls");
for(int i = 0; i <= 15; i ++) {
for(int j = 0; j <= 15; j ++) {
if(a[1].x == i && a[1].y == j) printf("①");
else if(a[2].x == i && a[2].y == j) printf("②");
else if(a[3].x == i && a[3].y == j) printf("③");
else if (wall[i][j] == 1) printf("■");
else if(block[i][j] == 1) 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);
printf("玩家三 生命值 %d %d● %d级炸弹 爆炸时间 %dms\n", a[3].life, a[3].bown - a[3].nom_bown, a[3].fire, a[3].time);
}
void in_to() {
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].life > 0) {
-- 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].life > 0) {
++ 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].life > 0) {
-- 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].life > 0) {
++ 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].life > 0) {
-- 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].life > 0) {
++ 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].life > 0) {
-- 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].life > 0) {
++ a[2].y;
}
if(c == 13 && a[1].nom_bown < a[1].bown && a[1].life > 0) {
++ 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 && a[2].life > 0) {
++ 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;
}
}
void happily() {
for(int i = start; i <= num; i ++) {
if(clock() >= b[i].time) {
++ start;
-- a[b[i].from].nom_bown;
if (b[i].from == 3) {
last = 0;
}
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;
if(a[3].x == j && a[3].y == b[i].y) a[3].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;
if(a[3].x == j && a[3].y == b[i].y) a[3].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(a[3].x == b[i].x && a[3].y == j) a[3].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(a[3].x == b[i].x && a[3].y == j) a[3].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[3].x][a[3].y] == 1) {
thing[a[3].x][a[3].y] = 0;
++ a[3].bown;
}
if(thing[a[3].x][a[3].y] == 2) {
thing[a[3].x][a[3].y] = 0;
++ a[3].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[3].x][a[3].y] == 3) {
thing[a[3].x][a[3].y] = 0;
a[3].time -= a[3].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;
}
if(thing[a[3].x][a[3].y] == 4) {
thing[a[3].x][a[3].y] = 0;
a[3].life += 5;
}
}
bool nothing(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
for (int i = min(y2, y1); i <= max(y1, y2); i ++) {
if (wall[x1][i] || block[x1][i] || bow(x1, i)) {
return false;
}
}
}
if (y1 == y2) {
for (int i = min(x1, x2); i <= max(x1, x2); i ++) {
if (wall[i][y1] || block[i][y1] || bow(i, y1)) {
return false;
}
}
}
return true;
}
struct coor {
int x, y;
int dis;
};
void move_by_AI() {
if (bow(a[3].x, a[3].y)) {
if (wall[a[3].x + 1][a[3].y] == 0 && block[a[3].x + 1][a[3].y] == 0 && bow(a[3].x + 1, a[3].y) == false) {
++ a[3].x;
return ;
}
if (wall[a[3].x - 1][a[3].y] == 0 && block[a[3].x - 1][a[3].y] == 0 && bow(a[3].x - 1, a[3].y) == false) {
-- a[3].x;
return ;
}
if (wall[a[3].x][a[3].y + 1] == 0 && block[a[3].x][a[3].y + 1] == 0 && bow(a[3].x, a[3].y + 1) == false) {
++ a[3].y;
return ;
}
if (wall[a[3].x][a[3].y - 1] == 0 && block[a[3].x][a[3].y - 1] == 0 && bow(a[3].x, a[3].y - 1) == false) {
-- a[3].y;
return ;
}
}
bool vis = false;
for (int i = a[3].x + 1; i <= 14 && wall[i][a[3].y] == 0 && block[i][a[3].y] == 0; i ++) {
if (bow(i, a[3].y)) {
vis = true;
break;
}
}
for (int i = a[3].x - 1; i >= 1 && wall[i][a[3].y] == 0 && block[i][a[3].y] == 0; i --) {
if (bow(i, a[3].y)) {
vis = true;
break;
}
}
if (vis) {
if (block[a[3].x][a[3].y - 1] == 0 && wall[a[3].x][a[3].y - 1] == 0 && a[3].y > 2 && bow(a[3].x, a[3].y - 1) == false) {
-- a[3].y;
return ;
}
if (block[a[3].x][a[3].y + 1] == 0 && wall[a[3].x][a[3].y + 1] == 0 && a[3].y < 14 && bow(a[3].x, a[3].y + 1) == false) {
++ a[3].y;
return ;
}
bool up = true, down = true;
for (int i = 1; i + a[3].x <= 14 || a[3].x - i >= 1; i ++) {
if (block[i + a[3].x][a[3].y] || wall[i + a[3].x][a[3].y] || bow(i + a[3].x, a[3].y)) {
up = false;
}
if (block[a[3].x - i][a[3].y] || wall[a[3].x - i][a[3].y] || bow(a[3].x - i, a[3].y)) {
down = false;
}
if (up) {
if (block[a[3].x + i][a[3].y - 1] == 0 && wall[a[3].x + i][a[3].y - 1] == 0 && bow(a[3].x + i, a[3].y - 1) == false) {
++ a[3].x;
return ;
}
if (block[a[3].x + i][a[3].y + 1] == 0 && wall[a[3].x + i][a[3].y + 1] == 0 && bow(a[3].x + i, a[3].y + 1) == false) {
++ a[3].x;
return ;
}
}
if (down) {
if (block[a[3].x - i][a[3].y - 1] == 0 && wall[a[3].x - i][a[3].y - 1] == 0 && bow(a[3].x - i, a[3].y - 1) == false) {
-- a[3].x;
return ;
}
if (block[a[3].x - i][a[3].y + 1] == 0 && wall[a[3].x - i][a[3].y + 1] == 0 && bow(a[3].x - i, a[3].y + 1) == false) {
-- a[3].x;
return ;
}
}
}
}
vis = false;
for (int i = a[3].y + 1; i <= 14 && wall[a[3].x][i] == 0 && block[a[3].x][i] == 0; i ++) {
if (bow(a[i].x, i)) {
vis = true;
break;
}
}
for (int i = a[3].y - 1; i >= 1 && wall[a[3].x][i] == 0 && block[a[3].x][i] == 0; i --) {
if (bow(a[i].x, i)) {
vis = true;
break;
}
}
if (vis) {
// while (true);
if (block[a[3].x - 1][a[3].y] == 0 && wall[a[3].x - 1][a[3].y] == 0 && bow(a[3].x - 1, a[3].y) == false) {
-- a[3].x;
return ;
}
if (block[a[3].x + 1][a[3].y] == 0 && wall[a[3].x + 1][a[3].y] == 0 && bow(a[3].x + 1, a[3].y) == false) {
++ a[3].x;
return ;
}
bool left = true, right = false;
for (int i = 1; i + a[3].y <= 14 || a[3].y - i >= 1; i ++) {
if (block[a[3].x][a[3].y + i] || wall[a[3].x][a[3].y + i] || bow(a[3].x, a[3].y + i)) {
right = false;
}
if (block[a[3].x][a[3].y - i] || wall[a[3].x][a[3].y - i] || bow(a[3].x, a[3].y - i)) {
left = false;
}
if (right) {
if (block[a[3].x - 1][a[3].y + i] && wall[a[3].x - 1][a[3].y + i] && bow(a[3].x - 1, a[3].y + i) == false) {
++ a[3].y;
return ;
}
if (block[a[3].x + 1][a[3].y + i] && wall[a[3].x + 1][a[3].y + i] && bow(a[3].x + 1, a[3].y + i) == false) {
++ a[3].y;
return ;
}
}
if (left) {
if (block[a[3].x - 1][a[3].y - i] && wall[a[3].x - 1][a[3].y - i] && bow(a[3].x - 1, a[3].y - i) == false) {
-- a[3].y;
return ;
}
if (block[a[3].x + 1][a[3].y - i] && wall[a[3].x + 1][a[3].y - i] && bow(a[3].x + 1, a[3].y - i) == false) {
-- a[3].y;
return ;
}
}
}
}
vis = false;
if (a[1].x == a[3].x && abs(a[1].y - a[3].y) <= a[3].fire && nothing(a[1].x, a[1].y, a[3].x, a[3].y)) {
++ num;
b[num].x = a[3].x;
b[num].y = a[3].y;
b[num].time = clock() + a[3].time;
b[num].from = 3;
++ a[3].nom_bown;
return ;
}
if (a[1].y == a[3].y && abs(a[1].x - a[3].x) <= a[3].fire && nothing(a[1].x, a[1].y, a[3].x, a[3].y)) {
++ num;
b[num].x = a[3].x;
b[num].y = a[3].y;
b[num].time = clock() + a[3].time;
b[num].from = 3;
++ a[3].nom_bown;
return ;
}
if (a[2].x == a[3].x && abs(a[2].y - a[3].y) <= a[3].fire && nothing(a[2].x, a[2].y, a[3].x, a[3].y)) {
++ num;
b[num].x = a[3].x;
b[num].y = a[3].y;
b[num].time = clock() + a[3].time;
b[num].from = 3;
++ a[3].nom_bown;
return ;
}
if (a[2].y == a[3].y && abs(a[2].x - a[3].x) <= a[3].fire && nothing(a[2].x, a[2].y, a[3].x, a[3].y)) {
++ num;
b[num].x = a[3].x;
b[num].y = a[3].y;
b[num].time = clock() + a[3].time;
b[num].from = 3;
++ a[3].nom_bown;
return ;
}
if ((block[a[3].x][a[3].y + 1] || block[a[3].x][a[3].y - 1] || block[a[3].x + 1][a[3].y] || block[a[3].x - 1][a[3].y]) && a[3].nom_bown < a[3].bown && block[a[3].x][a[3].y] == 0) {
++ num;
b[num].x = a[3].x;
b[num].y = a[3].y;
b[num].time = clock() + a[3].time;
b[num].from = 3;
++ a[3].nom_bown;
return ;
}
queue <coor > q;
coor tmp;
tmp.x = a[3].x + 1, tmp.y = a[3].y, tmp.dis = 2;
q.push(tmp);
tmp.x --;
tmp.y --;
tmp.dis = 4;
q.push(tmp);
tmp.y ++;
tmp.x --;
tmp.dis = 8;
q.push(tmp);
tmp.x ++;
tmp.y ++;
tmp.dis = 6;
q.push(tmp);
bool flag[15][15];
memset(flag, false, sizeof flag);
while (q.size()) {
tmp = q.front();
q.pop();
if (flag[tmp.x][tmp.y] || wall[tmp.x][tmp.y] || bow(tmp.x, tmp.y)) {
continue;
}
if (block[tmp.x][tmp.y]) {
if (tmp.dis == 2 && block[a[3].x + 1][a[3].y] == 0 && wall[a[3].x + 1][a[3].y] == 0 && bow(a[3].x + 1, a[3].y) == false) {
++ a[3].x;
return ;
}
if (tmp.dis == 8 && block[a[3].x - 1][a[3].y] == 0 && wall[a[3].x - 1][a[3].y] == 0 && bow(a[3].x - 1, a[3].y) == false) {
-- a[3].x;
return ;
}
if (tmp.dis == 6 && block[a[3].x][a[3].y + 1] == 0 && wall[a[3].x][a[3].y + 1] == 0 && bow(a[3].x, a[3].y + 1) == false) {
++ a[3].y;
return ;
}
if (tmp.dis == 4 && block[a[3].x][a[3].y - 1] == 0 && wall[a[3].x][a[3].y - 1] == 0 && bow(a[3].x, a[3].y - 1) == false) {
-- a[3].y;
return ;
}
}
flag[tmp.x][tmp.y] = true;
tmp.x --;
q.push(tmp);
tmp.x ++;
tmp.y ++;
q.push(tmp);
tmp.y --;
tmp.x ++;
q.push(tmp);
tmp.x --;
tmp.y --;
q.push(tmp);
}
tmp.x = a[3].x + 1, tmp.y = a[3].y, tmp.dis = 2;
q.push(tmp);
tmp.x --;
tmp.y --;
tmp.dis = 4;
q.push(tmp);
tmp.y ++;
tmp.x --;
tmp.dis = 8;
q.push(tmp);
tmp.x ++;
tmp.y ++;
tmp.dis = 6;
q.push(tmp);
memset(flag, false, sizeof flag);
while (q.size()) {
tmp = q.front();
q.pop();
if (flag[tmp.x][tmp.y] || wall[tmp.x][tmp.y] || bow(tmp.x, tmp.y)) {
continue;
}
if ((a[1].x == tmp.x && a[1].y == tmp.y) || (a[2].x == tmp.x && a[2].y == tmp.y)) {
if (tmp.dis == 2 && block[a[3].x + 1][a[3].y] == 0 && wall[a[3].x + 1][a[3].y] == 0 && bow(a[3].x + 1, a[3].y) == false) {
++ a[3].x;
return ;
}
if (tmp.dis == 8 && block[a[3].x - 1][a[3].y] == 0 && wall[a[3].x - 1][a[3].y] == 0 && bow(a[3].x - 1, a[3].y) == false) {
-- a[3].x;
return ;
}
if (tmp.dis == 6 && block[a[3].x][a[3].y + 1] == 0 && wall[a[3].x][a[3].y + 1] == 0 && bow(a[3].x, a[3].y + 1) == false) {
++ a[3].y;
return ;
}
if (tmp.dis == 4 && block[a[3].x][a[3].y - 1] == 0 && wall[a[3].x][a[3].y - 1] == 0 && bow(a[3].x, a[3].y - 1) == false) {
-- a[3].y;
return ;
}
}
flag[tmp.x][tmp.y] = true;
tmp.x --;
q.push(tmp);
tmp.x ++;
tmp.y ++;
q.push(tmp);
tmp.y --;
tmp.x ++;
q.push(tmp);
tmp.x --;
tmp.y --;
q.push(tmp);
}
}
void PVE() {
a[1].life = 50;
a[3].life = 50;
a[1].fire = 1;
a[3].fire = 1;
a[1].bown = 1;
a[3].bown = 1;
a[1].x = 13;
a[1].y = 2;
a[2].x = 15;
a[2].y = 15;
a[3].x = 2;
a[3].y = 2;
a[1].time = 2000;
a[2].time = 2000;
a[3].time = 2000;
int ai = clock() + 100;
while (a[1].life > 0 && a[3].life > 0) {
put_map();
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 == 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;
}
}
happily();
if (clock() > ai) {
move_by_AI();
ai = clock() + 175;
}
Sleep(5);
}
if (a[1].life > 0) {
put("玩家一赢啦");
}
else {
put("智障人机赢啦");
}
}
void PVVE() {
a[1].life = 50;
a[2].life = 50;
a[3].life = 50;
a[1].fire = 1;
a[2].fire = 1;
a[3].fire = 1;
a[1].bown = 1;
a[2].bown = 1;
a[3].bown = 1;
a[1].x = 13;
a[1].y = 2;
a[2].x = 2;
a[2].y = 13;
a[3].x = 2;
a[3].y = 2;
a[1].time = 2000;
a[2].time = 2000;
a[3].time = 2000;
int ai = clock() + 100;
while ((a[1].life > 0 ? 1 : 0) + (a[2].life > 0 ? 1 : 0) + (a[3].life > 0 ? 1 : 0) >= 2) {
put_map();
if (kbhit()) { in_to(); }
happily();
if (clock() > ai) {
move_by_AI();
ai = clock() + 175;
}
Sleep(5);
}
if (a[1].life > 0) {
put("玩家一赢啦");
}
else if (a[2].life > 0){
put("玩家二获得胜利");
}
else {
put("智障人机赢啦");
}
}
void PVP() {
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) {
put("一虎杀两羊\n");
stop();
return ;
}
if(a[1].life > 0) {
put("二号在轰的一声巨响中消失了\n");
stop();
return ;
}
put("一号已升天\n");
}
int main() {
srand((unsigned)time(0));
put("c++炸弹人\n");
Sleep(1000);
while (true) {
for (int i = 0; i <= 14; i ++) {
for (int j = 0; j <= 14; j ++) {
wall[i][j] = wa[i][j], block[i][j] = bl[i][j];
}
}
memset(thing, 0, sizeof thing);
memset(b, 0, sizeof b);
num = 0;
start = 0;
system("cls");
put("模式:\n");
put(" A.PVP B.PVPVE C.PVE D.退出");
char ch = getch();
if (ch == 'A' || ch == 'a') {
PVP();
stop();
}
if (ch == 'B' || ch == 'b') {
PVVE();
stop();
}
if (ch == 'C' || ch == 'c') {
PVE();
stop();
}
if (ch == 'D' || ch == 'd') {
system("cls");
put("再见 拜~");
return 0;
}
}
return 0;
}