详见1.0
更新内容
新增模式「职业大乱斗」
#include <windows.h>
#include <conio.h>
#include <bits/stdc++.h>
struct player{
int x;
int y;
int ice_time;
int wrong_time;
int blind_time;
int repelled;
int mine;
bool life;
int job;
int dir;
int speed_time;
}a[5];
char map[201][11];
void put(char*p);
void put_map() {
for(int i = -5; i <= 4; i ++) {
for(int j = 1; j <= 10; j ++) {
if(i == 0 && j == a[1].y) printf("○");
else if(a[1].x + i == a[2].x && j == a[2].y) printf("●");
else if(map[a[1].x + i][j] == 0) printf(" ");
else if(map[a[1].x + i][j] == 1) printf("■");
else if(map[a[1].x + i][j] == 2) printf("▓");
}
printf(" ");
for(int j = 1; j <= 10; j ++) {
if(i == 0 && j == a[2].y) printf("○");
else if(a[2].x + i == a[1].x && j == a[1].y) printf("●");
else if(map[a[2].x + i][j] == 0) printf(" ");
else if(map[a[2].x + i][j] == 1) printf("■");
else if(map[a[2].x + i][j] == 2) printf("▓");
}
puts("");
}
printf("玩家一 ");
if(a[1].ice_time > clock() && a[1].wrong_time < clock()) {
printf("冰冻状态 ");
}
else if(a[1].wrong_time > clock() && a[1].ice_time < clock()) {
printf("混乱状态 ");
}
else if(a[1].wrong_time > clock()) {
printf("混乱状态 冰冻状态");
}
else printf("正常状态 ");
printf(" 玩家二 ");
if(a[2].ice_time > clock() && a[2].wrong_time < clock()) {
printf("冰冻状态 ");
}
else if(a[2].wrong_time > clock() && a[2].ice_time < clock()) {
printf("混乱状态 ");
}
else if(a[2].wrong_time > clock()) {
printf("混乱状态 冰冻状态");
}
else printf("正常状态 ");
puts("");
printf("技能点:%2d 技能点:%2d", a[1].mine, a[2].mine);
}
void game_one() {
srand(unsigned(time(0)));
for(int i = 1; i <= 200; i += 3) {
map[i][1] = 1;
map[i][10] = 1;
for(int j = 2; j <= 9; j ++) {
map[i][j] = 1;
}
if(i != 1) {
map[i - 1][1] = 1;
map[i - 1][10] = 1;
map[i - 2][1] = 1;
map[i - 2][10] = 1;
for(int j = i - 2; j <= i - 1; j ++) {
for(int k = 2; k <= 9; k ++) {
map[j][k] = 0;
}
}
int index = rand() % 7 + 2;
map[i][index] = 0;
map[i][index + 1] = 0;
}
}
for(int i = 1; i <= 10; i ++) {
map[200][i] = 1;
}
a[1].x = 2;
a[1].y = 2;
a[2].x = 2;
a[2].y = 2;
a[1].ice_time = 0;
a[1].wrong_time = 0;
a[2].ice_time = 0;
a[2].wrong_time = 0;
a[1].mine = 0;
a[1].mine = 0;
while(a[1].x <= 198 && a[2].x <= 198) {
if(kbhit()) {
char c = getch();
if(c == -32) {
c = getch();
if(a[1].ice_time > clock()) {
;
}
else if(a[1].wrong_time > clock()) {
srand(unsigned(time(0)));
int s = rand() % 2;
if(s == 0 && map[a[1].x][a[1].y - 1] != 1) -- a[1].y;
else if(map[a[1].x][a[1].y + 1] != 1) ++ a[1].y;
}
else if(c == 75 && map[a[1].x][a[1].y - 1] != 1) {
-- a[1].y;
}
else if(c == 77 && map[a[1].x][a[1].y + 1] != 1) {
++ a[1].y;
}
else if(c == 72 && a[1].x % 3 == 0) {
a[1].x -= 2;
}
}
if(c == 'a' || c == 'w' || c == 'd') {
if(a[2].ice_time > clock()) {
;
}
else if(a[2].wrong_time > clock()) {
srand(unsigned(time(0)));
int s = rand() % 2;
if(s == 0 && map[a[2].x][a[2].y - 1] != 1) -- a[2].y;
else if(map[a[2].x][a[2].y + 1] != 1) ++ a[2].y;
}
else if(c == 'a' && map[a[2].x][a[2].y - 1] != 1) {
-- a[2].y;
}
else if(c == 'd' && map[a[2].x][a[2].y + 1] != 1) {
++ a[2].y;
}
else if(c == 'w' && a[2].x % 3 == 0) {
a[2].x -= 2;
}
}
if(c == '0' && a[1].mine >= 1) {
-- a[1].mine;
map[a[1].x + 1][a[1].y] = 0;
}
if(c == '.' && a[1].mine >= 1) {
-- a[1].mine;
map[a[1].x][a[1].y] = 1;
}
if(c == 13 && a[1].mine >= 1) {
-- a[1].mine;
srand(unsigned(time(0)));
int s = rand() % 2;
if(s == 1) a[2].ice_time = clock() + 2000;
else a[2].wrong_time = clock() + 3000;
}
if(c == 'b' && a[2].mine >= 1) {
-- a[2].mine;
map[a[2].x + 1][a[2].y] = 0;
}
if(c == 'n' && a[2].mine >= 1) {
-- a[2].mine;
map[a[2].x][a[2].y] = 1;
}
if(c == 'm' && a[2].mine >= 1) {
-- a[2].mine;
srand(unsigned(time(0)));
int s = rand() % 2;
if(s == 1) a[1].ice_time = clock() + 2000;
else a[1].wrong_time = clock() + 3000;
}
}
srand(unsigned(time(0)));
if(rand() % 3 == 0) {
int temp = rand() % 200;
if(temp % 3 == 1) ++ temp;
map[temp][rand() % 8 + 2] = 2;
}
if(map[a[1].x][a[1].y] == 2) {
++ a[1].mine;
map[a[1].x][a[1].y] = 0;
}
if(map[a[2].x][a[2].y] == 2) {
++ a[2].mine;
map[a[2].x][a[2].y] = 0;
}
if(map[a[1].x + 1][a[1].y] != 1) ++ a[1].x;
if(map[a[2].x + 1][a[2].y] != 1) ++ a[2].x;
put_map();
Sleep(20);
system("cls");
}
system("cls");
if(a[1].x == 199) put("一号首先逃脱");
else put("二号首先逃脱");
Sleep(1000);
}
void map_put(int x) {
for(int i = -5; i <= 4; i ++) {
for(int j = 1; j <= 10; j ++) {
if(i + a[1].x <= x) printf("▓");
else if(i == 0 && j == a[1].y) printf("○");
else if(a[1].x + i == a[2].x && j == a[2].y) printf("●");
else if(map[a[1].x + i][j] == 0) printf(" ");
else if(map[a[1].x + i][j] == 1) printf("■");
}
printf(" ");
for(int j = 1; j <= 10; j ++) {
if(i + a[2].x <= x) printf("▓");
else if(i == 0 && j == a[2].y) printf("○");
else if(a[2].x + i == a[1].x && j == a[1].y) printf("●");
else if(map[a[2].x + i][j] == 0) printf(" ");
else if(map[a[2].x + i][j] == 1) printf("■");
}
puts("");
}
}
void game_two() {
srand(unsigned(time(0)));
for(int i = 1; i <= 200; i += 3) {
map[i][1] = 1;
map[i][10] = 1;
for(int j = 2; j <= 9; j ++) {
map[i][j] = 1;
}
if(i != 1) {
map[i - 1][1] = 1;
map[i - 1][10] = 1;
map[i - 2][1] = 1;
map[i - 2][10] = 1;
for(int j = i - 2; j <= i - 1; j ++) {
for(int k = 2; k <= 9; k ++) {
map[j][k] = 0;
}
}
int index = rand() % 7 + 2;
map[i][index] = 0;
map[i][index + 1] = 0;
}
}
for(int i = 1; i <= 10; i ++) {
map[200][i] = 1;
}
a[1].life = true;
a[2].life = true;
a[1].x = 2;
a[1].y = 2;
a[2].x = 2;
a[2].y = 2;
int x = 1;
int fire_time = clock() + 5000;
while((a[1].x <= 198 || a[1].y <= 198) && (a[1].life && a[2].life)) {
if(kbhit()) {
char c = getch();
if(c == -32) {
c = getch();
if(c == 75 && map[a[1].x][a[1].y - 1] != 1 && a[1].life) {
-- a[1].y;
}
else if(c == 77 && map[a[1].x][a[1].y + 1] != 1 && a[1].life) {
++ a[1].y;
}
else if(c == 72 && map[a[1].x - 1][a[1].y] == 1 && a[1].life) {
a[1].x -= 2;
}
}
if(c == 'a' || c == 'w' || c == 'd') {
if(c == 'a' && map[a[2].x][a[2].y - 1] != 1 && a[2].life) {
-- a[2].y;
}
else if(c == 'd' && map[a[2].x][a[2].y + 1] != 1 && a[2].life) {
++ a[2].y;
}
else if(c == 'w' && map[a[2].x - 1][a[2].y] == 1 && a[2].life) {
a[2].x -= 2;
}
}
}
if(clock() > fire_time) {
++ x;
fire_time += 180;
}
if(a[1].x <= x) a[1].life = false;
if(a[2].x <= x) a[2].life = false;
map_put(x);
if(map[a[1].x + 1][a[1].y] != 1) ++ a[1].x;
if(map[a[2].x + 1][a[2].y] != 1) ++ a[2].x;
Sleep(20);
system("cls");
}
if(a[1].life && a[2].life) put("全部逃脱成功");
else if(a[1].life) put("二号试图在岩浆里游泳");
else if(a[2].life) put("一号化为了灰烬");
else put("黑人抬走一、二号");
Sleep(1000);
}
void mut_pap(int x) {
for(int i = -5; i <= 4; i ++) {
for(int j = 1; j <= 10; j ++) {
if(i + a[1].x <= x) printf("▓");
else if(i == 0 && j == a[1].y) printf("○");
else if(a[1].x + i == a[2].x && j == a[2].y) printf("●");
else if(map[a[1].x + i][j] == 0) printf(" ");
else if(map[a[1].x + i][j] == 1) printf("■");
}
puts("");
}
}
void game_four() {
srand(unsigned(time(0)));
for(int i = 1; i <= 200; i += 3) {
map[i][1] = 1;
map[i][10] = 1;
for(int j = 2; j <= 9; j ++) {
map[i][j] = 1;
}
if(i != 1) {
map[i - 1][1] = 1;
map[i - 1][10] = 1;
map[i - 2][1] = 1;
map[i - 2][10] = 1;
for(int j = i - 2; j <= i - 1; j ++) {
for(int k = 2; k <= 9; k ++) {
map[j][k] = 0;
}
}
int index = rand() % 7 + 2;
map[i][index] = 0;
map[i][index + 1] = 0;
}
}
for(int i = 1; i <= 10; i ++) {
map[200][i] = 1;
}
a[1].life = true;
a[1].x = 2;
a[1].y = 2;
int x = 1;
int fire_time = clock() + 5000;
while(a[1].x <= 198 && a[1].life) {
if(kbhit()) {
char c = getch();
if(c == -32) {
c = getch();
if(c == 75 && map[a[1].x][a[1].y - 1] != 1 && a[1].life) {
-- a[1].y;
}
else if(c == 77 && map[a[1].x][a[1].y + 1] != 1 && a[1].life) {
++ a[1].y;
}
else if(c == 72 && map[a[1].x - 1][a[1].y] == 1 && a[1].life) {
a[1].x -= 2;
}
}
}
if(clock() > fire_time) {
++ x;
fire_time += 180;
}
if(a[1].x <= x) a[1].life = false;
mut_pap(x);
if(map[a[1].x + 1][a[1].y] != 1) ++ a[1].x;
Sleep(20);
system("cls");
}
if(a[1].life) put("逃脱成功");
Sleep(1000);
}
void pap_mut() {
for(int i = -5; i <= 4; i ++) {
for(int j = 1; j <= 10; j ++) {
if(i == 0 && j == a[1].y) printf("○");
else if(a[1].x + i == a[2].x && j == a[2].y) printf("●");
else if(map[a[1].x + i][j] == 0) printf(" ");
else if(map[a[1].x + i][j] == 1) printf("■");
}
puts("");
}
}
void game_three() {
srand(unsigned(time(0)));
for(int i = 1; i <= 200; i += 3) {
map[i][1] = 1;
map[i][10] = 1;
for(int j = 2; j <= 9; j ++) {
map[i][j] = 1;
}
if(i != 1) {
map[i - 1][1] = 1;
map[i - 1][10] = 1;
map[i - 2][1] = 1;
map[i - 2][10] = 1;
for(int j = i - 2; j <= i - 1; j ++) {
for(int k = 2; k <= 9; k ++) {
map[j][k] = 0;
}
}
int index = rand() % 7 + 2;
map[i][index] = 0;
map[i][index + 1] = 0;
}
}
for(int i = 1; i <= 10; i ++) {
map[200][i] = 1;
}
a[1].life = true;
a[1].x = 2;
a[1].y = 2;
int start_time = clock();
while(a[1].x <= 198 && a[1].life) {
if(kbhit()) {
char c = getch();
if(c == -32) {
c = getch();
if(c == 75 && map[a[1].x][a[1].y - 1] != 1 && a[1].life) {
-- a[1].y;
}
else if(c == 77 && map[a[1].x][a[1].y + 1] != 1 && a[1].life) {
++ a[1].y;
}
else if(c == 72 && map[a[1].x - 1][a[1].y] == 1 && a[1].life) {
a[1].x -= 2;
}
}
}
pap_mut();
if(map[a[1].x + 1][a[1].y] != 1) ++ a[1].x;
Sleep(20);
system("cls");
}
printf("共计用时%lfs", double(clock() - start_time) / 100);
}
void put(char *p) {
while(1) {
if(*p != 0)
printf("%c", *p ++);
else
break;
Sleep(80);
}
}
void pu_ma() {
for(int i = -5; i <= 4; i ++) {
for(int j = 1; j <= 10; j ++) {
if(i == 0 && j == a[1].y) printf("○");
else if (a[1].blind_time > clock()) {
int k = rand() % 4;
if(k == 0 || k == 3) printf(" ");
else if(k == 1) printf("■");
else if(k == 2) printf("▓");
}
else if(a[1].x + i == a[2].x && j == a[2].y) printf("●");
else if(map[a[1].x + i][j] == 0) printf(" ");
else if(map[a[1].x + i][j] == 1) printf("■");
else if(map[a[1].x + i][j] == 2) printf("▓");
}
printf(" ");
for(int j = 1; j <= 10; j ++) {
if(i == 0 && j == a[2].y) printf("○");
else if (a[2].blind_time > clock()) {
int k = rand() % 4;
if(k == 0 || k == 3) printf(" ");
else if(k == 1) printf("■");
else if(k == 2) printf("▓");
}
else if(a[2].x + i == a[1].x && j == a[1].y) printf("●");
else if(map[a[2].x + i][j] == 0) printf(" ");
else if(map[a[2].x + i][j] == 1) printf("■");
else if(map[a[2].x + i][j] == 2) printf("▓");
}
puts("");
}
printf("玩家一 ");
if(a[1].blind_time > clock()) {
printf("盲人状态 ");
}
else printf("正常状态 ");
printf(" 玩家二 ");
if(a[1].blind_time > clock()) {
printf("盲人状态 ");
}
else printf("正常状态 ");
puts("");
printf("等级:%2d 等级:%2d", a[1].mine, a[2].mine);
}
void game_five() {
int win[3];
win[1] = 0, win[2] = 0;
a[1].repelled = 1;
a[2].repelled = 1;
system("cls");
put("玩家1职业:\n左右选择 空格确定");
char x;
int temp = 1;
while(true) {
if(temp == 1) {
system("cls");
printf("墨鱼小哥\n击退提升正常,被击中有失明效果");
}
if (temp == 2) {
system("cls");
printf("道士\n击退提升翻倍,无效果");
}
if (temp == 3) {
system("cls");
printf("嫉妒者(还没想好)\n技能:幸灾乐祸,击中对手后有加速");
}
x = getch();
if(x == -32) {
x = getch();
if(x == 75 && temp > 1) -- temp;
if(x == 77 && temp < 3) ++ temp;
}
if (x == ' ') {
a[1].job = temp;
break;
}
}
system("cls");
put("玩家2职业:\n左右选择 空格确定");
temp = 1;
while(true) {
if(temp == 1) {
system("cls");
printf("墨鱼小哥\n技能:墨鱼助我,击退提升正常,被击中有失明效果");
}
if (temp == 2) {
system("cls");
printf("道士\n技能:替天行道,击退提升翻倍,无效果");
}
if (temp == 3) {
system("cls");
printf("嫉妒者(还没想好)\n技能:幸灾乐祸,击中对手后有加速");
}
x = getch();
if(x == -32) {
x = getch();
if(x == 75 && temp > 1) -- temp;
if(x == 77 && temp < 3) ++ temp;
}
if (x == ' ') {
a[2].job = temp;
break;
}
}
srand(unsigned(time(0)));
memset(map, 0, sizeof map);
for(int i = 1; i <= 200; i += 3) {
map[i][1] = 1;
map[i][10] = 1;
for(int j = 2; j <= 9; j ++) {
map[i][j] = 1;
}
if(i != 1) {
map[i - 1][1] = 1;
map[i - 1][10] = 1;
map[i - 2][1] = 1;
map[i - 2][10] = 1;
for(int j = i - 2; j <= i - 1; j ++) {
for(int k = 2; k <= 9; k ++) {
map[j][k] = 0;
}
}
int k = rand() % 3;
if (k == 0) {
int index1 = rand() % 8 + 2, index2 = rand() % 8 + 2;
map[i][index1] = 0;
map[i][index2] = 0;
}
else {
int index = rand() % 7 + 2;
map[i][index] = map[i][index + 1] = 0;
}
}
}
for(int i = 1; i <= 10; i ++) {
map[200][i] = 1;
}
a[1].x = 2;
a[1].y = 2;
a[2].x = 2;
a[2].y = 2;
a[1].dir = a[2].dir = 6;
a[1].blind_time = a[2].blind_time = clock();
a[1].repelled = a[2].repelled = 1;
a[1].speed_time = a[2].speed_time = clock();
a[1].mine = a[2].mine = 1;
while (a[1].repelled != 5 && a[2].repelled != 5) {
if(kbhit()) {
char c = getch();
if(c == -32) {
c = getch();
if(c == 75 && map[a[1].x][a[1].y - 1] != 1) {
-- a[1].y;
if (a[1].speed_time > clock() && x != 3) -- a[1].y;
a[1].dir = 4;
}
else if(c == 77 && map[a[1].x][a[1].y + 1] != 1) {
++ a[1].y;
if (a[1].speed_time > clock() && x != 8) ++ a[1].y;
a[1].dir = 6;
}
else if(c == 72 && a[1].x % 3 == 0) {
a[1].x -= 2;
}
else if (c == 80) {
if (a[1].dir == 4) {
if (a[2].x == a[1].x && a[2].y == a[1].y - 1) {
a[2].y -= a[1].mine;
if (a[2].y <= 1) a[2].y = 2;
if (a[1].job == 1) a[2].blind_time = clock() + 3000;
if (a[1].job == 3) a[1].speed_time = clock() + 1500;
}
}
if (a[1].dir == 6) {
if (a[2].x == a[1].x && a[2].y == a[1].y + 1) {
a[2].y += a[1].mine;
if (a[2].y >= 10) a[2].y = 9;
if (a[1].job == 1) a[2].blind_time = clock() + 3000;
if (a[1].job == 3) a[1].speed_time = clock() + 1500;
}
}
}
}
if(c == 'a' || c == 'w' || c == 'd' || c == 's') {
if(c == 'a' && map[a[2].x][a[2].y - 1] != 1) {
-- a[2].y;
if (a[2].speed_time > clock() && x != 3) -- a[2].y;
a[2].dir = 4;
}
else if(c == 'd' && map[a[2].x][a[2].y + 1] != 1) {
++ a[2].y;
if (a[2].speed_time > clock() && x != 8) ++ a[2].y;
a[2].dir = 6;
}
else if(c == 'w' && a[2].x % 3 == 0) {
a[2].x -= 2;
}
if (c == 's') {
if (a[2].dir == 4) {
if (a[1].x == a[2].x && a[1].y == a[2].y - 1) {
a[1].y -= a[2].mine;
if (a[1].y <= 1) a[1].y = 2;
if (a[2].job == 1) a[1].blind_time = clock() + 3000;
if (a[2].job == 3) a[2].speed_time = clock() + 1500;
}
}
if (a[2].dir == 6) {
if (a[1].x == a[2].x && a[1].y == a[2].y + 1) {
a[1].y += a[2].mine;
if (a[1].y >= 10) a[1].y = 9;
if (a[2].job == 1) a[1].blind_time = clock() + 3000;
if (a[2].job == 3) a[2].speed_time = clock() + 1500;
}
}
}
}
}
srand(unsigned(time(0)));
if(rand() % 3 == 0) {
int temp = rand() % 200;
if(temp % 3 == 1) ++ temp;
map[temp][rand() % 8 + 2] = 2;
}
if(map[a[1].x][a[1].y] == 2) {
int i = 3;
if (a[1].job == 2) i --;
i == 0 ? ++ a[1].mine : true;
map[a[1].x][a[1].y] = 0;
}
if(map[a[2].x][a[2].y] == 2) {
int i = rand() % 3;
if (a[2].job == 2) i --;
i == 0 ? ++ a[2].mine : true;
map[a[2].x][a[2].y] = 0;
}
if(map[a[1].x + 1][a[1].y] != 1) ++ a[1].x;
if(map[a[2].x + 1][a[2].y] != 1) ++ a[2].x;
if(a[1].x == 199) {
++ a[1].repelled;
a[1].x = 2;
}
if(a[2].x == 199) {
++ a[2].repelled;
a[2].x = 2;
}
pu_ma();
Sleep(20);
system("cls");
}
if (a[1].mine == 5) {
printf("1赢了");
}
else {
printf("2赢了");
}
Sleep(1000);
}
int main() {
put("c++小游戏");
put("塔");
Sleep(567);
char input;
while(true) {
system("cls");
put("a.孤寂模式 b.友尽模式 c.退出\n");
input = getch();
if(input == 'a') {
system("cls");
put("a.生存 b.测试 (除a,b什么都可以).返回");
input = getch();
if(input == 'a') {
game_four();
}
if(input == 'b') {
game_three();
}
if(input == 'c') {
continue;
}
}
else if(input == 'b') {
system("cls");
put("a.生存 b.竞赛 c.职业大乱斗 d.(除a,b什么都可以).返回");
input = getch();
if(input == 'a') {
game_two();
}
else if(input == 'b') {
game_one();
}
else if(input == 'c') {
game_five();
}
else if(input == 'd') {
continue;
}
else {
put("\n请不要乱按,谢谢配合");
system("pause");
}
}
else if(input == 'c') {
break;
}
else {
put("\n请不要乱按,谢谢配合");
system("pause");
}
}
system("cls");
put("欢迎下次游玩 谢谢");
return 0;
}