「游戏」c++岩浆逃脱 1.0

已更新至详见1.1
本游戏纯手打,无抄袭

单人模式(孤寂)

生存:努力逃脱上方的岩浆,取得胜利吧。
测试:测一测你究竟有多快。

双人模式(友尽)

生存:和朋友一起逃脱岩浆吧。
竞赛:互相设置陷阱,比比谁先逃脱!

玩家一:
	↑  ← → 控制移动;
	[0]    清空脚下那一格;
	[.]    放置方块;
	[回车] 给予玩家二一个状态;
	请看左边的图,黑圆是你,白圆是你的朋友。


玩家二:
	w a d控制移动
	[b]    清空脚下那一格
	[n]    放置方块
	[m]    给予玩家一一个状态
	请看右边的图,黑圆是你,白圆是你的朋友。

每次使用非移动功能键都是需要技能点的;
如果玩单人看到了别人没有关系,当他不存在就可以了。

#include <windows.h>
#include <conio.h>
#include <bits/stdc++.h>

struct player{
    int x;
    int y;
    int ice_time;
    int wrong_time;
    int mine;
    bool life;
}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);
    }
}

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.竞赛 (除a,b什么都可以).返回");
            input = getch();
            if(input == 'a') {
                game_two();
            }
            else if(input == 'b') {
                game_one();
            }
            else if(input == 'c') {
                continue;
            }
            else {
                put("\n请不要乱按,谢谢配合");
                system("pause");
            }
        }
        else if(input == 'c') {
            break;
        }
        else {
            put("\n请不要乱按,谢谢配合");
            system("pause");
        }
    }
    system("cls");
    put("欢迎下次游玩  谢谢");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/yu_______chen/article/details/107040807