经过一点点的努力,我把之前写的代码改精炼了些,然后也改了些内容,应该比以前要好玩些了
更新内容
去掉职业大乱斗(因为你打不到人)
改模式选择为规则调整
更改岩浆下降速度(更刺激了)
改为双视角同人物(一号在左边为空心圆 二号在右边为实心圆)
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <conio.h>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <windows.h>
using namespace std; //不要在意头文件
const int M = 15, N = 105;
int mapp[N][M];
string s[M] = { "" , "冰冻状态" , "混淆状态" , "黑暗状态" };
int num;
bool rule_attact , rule_poison , rule_lava;
int lava_position , lava_down_time;
struct player {
bool on;
int x , y;
int if_jump;
int effect[M];
int numm;
int direction;
int affect;
int st , timee;
bool survive;
}a[M];
void map_reset () {
lava_position = -5;
lava_down_time = 0;
num = 1;
for ( int i = 1 ; i <= 100 ; i += 3 ) {
for ( int j = 1 ; j <= 10 ; j ++ ) mapp[i][j] = 1;
mapp[i + 1][1] = mapp[i + 1][10] = mapp[i + 2][1] = mapp[i + 2][10] = 1;
mapp[i][rand () % 8 + 2] = 0;
}
for ( int j = 1 ; j <= 10 ; j ++ ) {
mapp[100][j] = 1;
}
}
void player_reset () {
a[1].x = a[2].x = 3;
a[1].y = a[2].y = 2;
a[1].if_jump = a[2].if_jump = 0;
a[1].direction = a[2].direction = 1;
a[1].affect = a[2].affect = 0;
a[1].numm = a[2].numm = 0;
a[1].st = a[2].st = 0;
a[2].on = false;
a[1].survive = a[2].survive = true;
}
void put_map () {
for ( int i = -3 ; i <= 3 ; i ++ ) {
for ( int j = 1 ; j <= 10 ; j ++ ) {
if ( i == 0 && j == a[1].y ) printf ( "○" );
else if ( a[1].x + i <= lava_position ) printf ( "▓" );
else if ( a[1].effect[3] > clock () ) printf("**");
else if ( a[1].x + i == a[2].x && j == a[2].y && a[2].on ) printf ( "●" );
else if ( mapp[a[1].x + i][j] == 1 ) printf ( "█" );
else if ( mapp[a[1].x + i][j] == 2 ) printf ( "☆" );
else printf( " " );
}
printf( " " );
if ( a[2].on ) {
for ( int j = 1 ; j <= 10 ; j ++ ) {
if ( i == 0 && j == a[2].y ) printf ( "●" );
else if ( a[2].x + i <= lava_position ) printf ( "▓" );
else if ( a[2].effect[3] > clock () ) printf("**");
else if ( a[2].x + i == a[1].x && j == a[1].y ) printf ( "○" );
else if ( mapp[a[2].x + i][j] == 1 ) printf ( "█" );
else if ( mapp[a[2].x + i][j] == 2 ) printf ( "☆" );
else printf ( " " );
}
}
printf ( "\n" );
}
for ( int i = 1 ; i <= 10 ; i ++ ) {
if ( a[1].effect[i] > clock () ) {
cout << s[i] << " ";
}
else cout << " ";
if ( a[2].effect[i] > clock () && a[2].on ) {
cout << s[i];
}
cout << endl;
}
if ( rule_poison ) {
printf ( "药水:%2d" , a[1].affect);
if ( a[2].on ) printf (" 药水:%2d" , a[2].affect );
printf ( "\n" );
}
if ( num != 1) {
printf ( "圈数:%2d" , a[1].numm);
if ( a[2].on ) printf (" 圈数:%2d" , a[2].numm);
printf ( "\n" );
}
printf ( "用时:%2dmin%2ds%dms" , ( a[1].st == 0 ? 0 : clock () - a[1].st ) / 60000 , ( a[1].st == 0 ? 0 : clock () - a[1].st ) % 60000 / 1000 , ( a[1].st == 0 ? 0 : clock () - a[1].st ) % 1000);
if ( a[2].on ) printf (" 用时:%2dmin%2ds%dms" , (a[2].st == 0 ? 0 : clock () - a[2].st ) / 60000 , ( a[2].st == 0 ? 0 : clock () - a[2].st ) % 60000 / 1000 , ( a[2].st == 0 ? 0 : clock () - a[2].st ) % 1000 );
}
void move () {
if ( kbhit() ) {
char c = getch ();
if ( a[1].effect[1] <= clock () ) {
if ( a[1].effect[2] > clock () && ( c == 'a' || c == 'd' ) ) c = time (0) % 2 == 1 ? 'd' : 'a';
if ( c == 'a' && a[1].y != 2 ) a[1].y -- , a[1].direction = -1;
if ( c == 'd' && a[1].y != 9 ) a[1].y ++ , a[1].direction = 1;
if ( c == 'w' && a[1].x % 3 == 0 ) {
a[1].if_jump = clock() + 100;
}
if ( c == 's' && rule_attact && a[1].y + a[1].direction == a[2].y && a[2].y + a[1].direction != 1 && a[2].y + a[1].direction != 10 ) a[2].y += a[1].direction;
}
if ( c == -32 && a[2].effect[1] <= clock () ) {
c = getch();
if ( a[2].effect[2] > clock () && ( c == 75 || c == 77 ) ) c = time (0) % 2 == 1 ? 77 : 75;
if ( c == 75 && a[2].y != 2 ) a[2].y -- , a[2].direction = -1;
if ( c == 77 && a[2].y != 9 ) a[2].y ++ , a[2].direction = 1;
if ( c == 72 && a[2].x % 3 == 0 ) {
a[2].if_jump = clock() + 100;
}
if ( c == 80 && rule_attact && a[2].y + a[2].direction == a[1].y && a[1].y + a[2].direction != 1 && a[1].y + a[2].direction != 10 ) a[1].y += a[2].direction;
}
if ( c == ' ' && a[1].affect > 0) {
a[1].affect --;
a[2].effect[rand () % 4 + 1] = clock() + 3000;
}
if ( c == '0' && a[2].affect > 0) {
a[2].affect --;
a[1].effect[rand () % 4 + 1] = clock() + 3000;
}
}
if ( a[1].if_jump <= clock() ) {
if ( mapp[a[1].x + 1][a[1].y] != 1 )
a[1].x ++;
}
else a[1].x --;
if ( a[2].if_jump <= clock() ) {
if ( mapp[a[2].x + 1][a[2].y] != 1 )
a[2].x ++;
}
else a[2].x --;
}
void run () {
int t = clock () + 1000;
bool flag_ = true , flag__ = true;
if ( rule_lava ) lava_down_time = clock () + 300;
while ( ( a[1].numm < num || ( a[2].numm < num && a[2].on ) ) && ( a[1].survive || a[2].survive ) ) {
if ( clock () > lava_down_time && lava_down_time != 0) lava_position ++ , lava_down_time = clock () + rand () % 500 + 50;
if ( t <= clock () && rule_poison ) {
mapp[rand () % 34 * 3][rand () % 8 + 2] = 2;
t = clock () + 5000;
}
if ( flag_ && ( a[1].x != 3 || a[1].y != 2 ) ) a[1].st = clock () , flag_ = false;
if ( flag__ && ( a[2].x != 3 || a[2].y != 2 ) ) a[2].st = clock () , flag__ = false;
put_map ();
move ();
if ( mapp[a[1].x][a[1].y] == 2 ) a[1].affect ++ , mapp[a[1].x][a[1].y] = 0;
if ( mapp[a[2].x][a[2].y] == 2 ) a[2].affect ++ , mapp[a[2].x][a[2].y] = 0;
Sleep (100);
system ( "cls" );
if ( a[1].x <= lava_position ) a[1].effect[1] = 2147483647 , a[1].survive = false;
if ( a[2].x <= lava_position ) a[2].effect[1] = 2147483647 , a[2].survive = false;
if ( a[1].x == 99 ) {
a[1].numm ++;
a[1].x = 0;
if ( a[1].numm == num ) a[1].timee = clock () - a[1].st;
}
if ( a[2].x == 99 ) {
a[2].numm ++;
a[2].x = 0;
if ( a[2].numm == num ) a[2].timee = clock () - a[2].st;
}
}
if (rule_lava) {
if ( a[1].survive ) printf ( "1号成功逃脱 " );
if ( a[2].survive && a[2].on ) printf ( "2号成功逃脱" );
}
else if (a[2].on)
printf ( "%d号玩家赢了,用时%d分%d秒%d毫秒" , a[1].timee < a[2].timee ? 1 : 2 , a[a[1].timee < a[2].timee ? 1 : 2].timee / 60000 , a[a[1].timee < a[2].timee ? 1 : 2].timee % 60000 / 1000 , a[a[1].timee < a[2].timee ? 1 : 2].timee % 1000 );
else printf ( "恭喜您,成功逃脱" );
return ;
}
void set_game () {
printf ( "欢迎游玩" );
Sleep (3000);
system ( "cls" );
printf ( "请确定规则\n" );
printf ( "方向键上下移动,空格更改选项,回车确认\n");
printf ( "圈数:%d\n" , num );
printf ( "药水:%s\n" , rule_poison ? "是" : "否" );
printf ( "攻击:%s\n" , rule_attact ? "是" : "否" );
printf ( "多人:%s\n" , a[2].on ? "是" : "否" );
printf ( "岩浆:%s\n" , rule_lava ? "是" : "否" );
char r;
HANDLE hout;
COORD coord;
hout = GetStdHandle(STD_OUTPUT_HANDLE);
coord.X = 6;
coord.Y = 2;
SetConsoleCursorPosition(hout, coord);
while ( r != 13 ) {
r = getch ();
coord.X = 3;
if ( r == -32 ) {
r = getch ();
if ( r == 72 ) {
coord.Y -= 1;
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
if ( r == 80 ) {
coord.Y += 1;
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
}
if ( r == ' ' && coord.Y == 2 && rule_lava == false) {
num = num % 10 + 1;
printf ( "%d " , num );
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
if ( r == ' ' && coord.Y == 3 ) {
rule_poison = !rule_poison;
printf( "%s" , rule_poison ? "是" : "否" );
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
if ( r == ' ' && coord.Y == 4 ) {
rule_attact = !rule_attact;
printf( "%s" , rule_attact ? "是" : "否" );
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
if ( r == ' ' && coord.Y == 5 ) {
a[2].on = !a[2].on;
printf( "%s" , a[2].on ? "是" : "否" );
coord.X = 6;
SetConsoleCursorPosition(hout, coord);
}
if ( r == ' ' && coord.Y == 6 ) {
rule_lava = !rule_lava;
printf( "%s" , rule_lava ? "是" : "否" );
num = 1;
coord.X = 6;
coord.Y = 2;
SetConsoleCursorPosition(hout, coord);
printf ( "1" );
coord.Y = 6;
SetConsoleCursorPosition(hout, coord);
}
Sleep (200);
}
}
int main () {
srand ( unsigned ( time (0) ) );
while ( true ) {
player_reset ();
map_reset ();
set_game ();
run ();
}
return 0;
}