跳到正文

休闲·娱乐

英超小游戏V1.0

GeorgeDeng约 22 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年10月28日
篇幅
约 22 分钟

版本

  1. v1当前

c++小游戏:英超模拟器1.0

24/25赛季的模拟器,非常 bug,经过 AI 调试才正式出版。预计 1.0.1 在 44 月份上线!

计划 1.0.1 更新内容:

  • 将训练次数允许叠加。

  • 添加胜场、平场和负场次计算。

  • 随机数比分缩小,避免出现类似于 1010 比 00 这样的比分。

  • 随机数能力值,否则大家都往强的选。

建议编译指令:-O2 -std=c++14 -Wl,-stack=536870912 -Wall。

C++
#include <iostream>
#include <cstdio>
#include <ctime>
#include <random>
#include <windows.h>
#include <algorithm>
using namespace std;

int vis[25]; // 全局 vis 数组
struct node {
    string name;
    int ablity;
    int point;
    int goal, lose;
    int train_remain;
} team[25];

int cli_team = 0;
int oponment;

bool cmp(node a, node b) {
    if (a.point != b.point) return a.point > b.point;
    if (a.goal - a.lose != b.goal - b.lose) return a.goal - a.lose > b.goal - b.lose;
    if (a.goal != b.goal) return a.goal > b.goal;
    return a.ablity > b.ablity;
}

void print_board() {
    node temp_team[25];
    for (int i = 1; i <= 20; i++) {
        temp_team[i] = team[i];
    }
    sort(temp_team + 1, temp_team + 1 + 20, cmp);
    cout << "Up Name Point Goal Lose" << endl;
    for (int i = 1; i <= 20; i++) {
        cout << i << ' ' << temp_team[i].name << ' ' << temp_team[i].point << ' ' << temp_team[i].goal << ' ' << temp_team[i].lose << ' ';
        if (temp_team[i].name == team[cli_team].name) {
            cout << "(My team)";
        }
        cout << endl;
    }
    system("pause");
    system("cls");
}

void play_game(int round) {
    if (round <= 19) {
        oponment = rand() % 20 + 1;
        while (vis[oponment] == 1 || oponment == cli_team) {
            oponment = rand() % 20 + 1;
        }
        vis[oponment]++;
        cout << "Your oponment: " << team[oponment].name << endl;
        system("pause");
        int result = rand() % (team[cli_team].ablity + team[oponment].ablity);
        if (result < team[cli_team].ablity) {
            cout << "You win by ";
            int my_points = rand() % 10;
            while (my_points == 0) my_points = rand() % 10;
            int you_points = rand() % 4;
            while (you_points >= my_points) {
                you_points = rand() % 4;
            }
            cout << my_points << '-' << you_points << "!" << endl;
            team[cli_team].point += 3;
            team[cli_team].goal += my_points;
            team[cli_team].lose += you_points;
            team[oponment].goal += you_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        } else if (result == team[cli_team].ablity) {
            cout << "You draw by ";
            int my_points = rand() % 10;
            cout << my_points << '-' << my_points << "!" << endl;
            team[cli_team].point += 1;
            team[oponment].point++;
            team[cli_team].goal += my_points;
            team[cli_team].lose += my_points;
            team[oponment].goal += my_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        } else {
            cout << "You lose by ";
            int my_points = rand() % 10;
            while (my_points == 0) my_points = rand() % 10;
            int you_points = rand() % 4;
            while (you_points >= my_points) {
                you_points = rand() % 4;
            }
            swap(my_points, you_points);
            cout << my_points << '-' << you_points << "!" << endl;
            team[oponment].point += 3;
            team[cli_team].goal += my_points;
            team[cli_team].lose += you_points;
            team[oponment].goal += you_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        }
    } else {
        oponment = rand() % 20 + 1;
        while (vis[oponment] == 2 || oponment == cli_team) {
            oponment = rand() % 20 + 1;
        }
        vis[oponment]++;
        cout << "Your oponment: " << team[oponment].name << endl;
        system("pause");
        int result = rand() % (team[cli_team].ablity + team[oponment].ablity);
        if (result < team[cli_team].ablity) {
            cout << "You win by ";
            int my_points = rand() % 10;
            while (my_points == 0) my_points = rand() % 10;
            int you_points = rand() % 4;
            while (you_points >= my_points) {
                you_points = rand() % 4;
            }
            cout << my_points << '-' << you_points << "!" << endl;
            team[cli_team].point += 3;
            team[cli_team].goal += my_points;
            team[cli_team].lose += you_points;
            team[oponment].goal += you_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        } else if (result == team[cli_team].ablity) {
            cout << "You draw by ";
            int my_points = rand() % 10;
            cout << my_points << '-' << my_points << "!" << endl;
            team[cli_team].point += 1;
            team[oponment].point++;
            team[cli_team].goal += my_points;
            team[cli_team].lose += my_points;
            team[oponment].goal += my_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        } else {
            cout << "You lose by ";
            int my_points = rand() % 10;
            while (my_points == 0) my_points = rand() % 10;
            int you_points = rand() % 4;
            while (you_points >= my_points) {
                you_points = rand() % 4;
            }
            swap(my_points, you_points);
            cout << my_points << '-' << you_points << "!" << endl;
            team[oponment].point += 3;
            team[cli_team].goal += my_points;
            team[cli_team].lose += you_points;
            team[oponment].goal += you_points;
            team[oponment].lose += my_points;
            system("pause");
            system("cls");
        }
    }
}

void play_others() {
    bool local_vis[25] = {false}; // 使用局部 vis 数组
    for (int i = 1; i <= 20; i++) {
        if (i == cli_team || i == oponment) continue;
        if (local_vis[i]) continue;
        local_vis[i] = true;
        int opn = rand() % 20 + 1;
        while (local_vis[opn] || opn == cli_team || opn == oponment) {
            opn = rand() % 20 + 1;
        }
        local_vis[opn] = true;
        if (team[i].ablity > team[opn].ablity) {
            team[i].point += 3;
            int add1 = rand() % 10 + 1;
            int add2 = rand() % add1;
            team[i].goal += add1, team[i].lose += add2;
            team[opn].goal += add2, team[opn].lose += add1;
        } else if (team[i].ablity == team[opn].ablity) {
            team[i].point += 1;
            team[opn].point += 1;
            int add1 = rand() % 10 + 1;
            int add2 = add1;
            team[i].goal += add1, team[i].lose += add2;
            team[opn].goal += add2, team[opn].lose += add1;
        } else {
            team[opn].point += 3;
            int add1 = rand() % 10 + 1;
            int add2 = rand() % add1;
            team[i].goal += add2, team[i].lose += add1;
            team[opn].goal += add1, team[opn].lose += add2;
        }
    }
}

int main() {
    srand(time(NULL));
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << "Priemer League" << endl;
    Sleep(200);
    system("cls");

    // 初始化球队
    team[1].name = "Liverpool";
    team[2].name = "Arsenal";
    team[3].name = "Aston Villa";
    team[4].name = "Manchester City";
    team[5].name = "Manchester United";
    team[6].name = "Tottenham Hotspur";
    team[7].name = "Newcastle United";
    team[8].name = "Chelsea";
    team[9].name = "Nottingham Forest";
    team[10].name = "Bernmouth";
    team[11].name = "Brighton";
    team[12].name = "Fulham";
    team[13].name = "Brentford";
    team[14].name = "Cristical Palace";
    team[15].name = "West Ham United";
    team[16].name = "Everton";
    team[17].name = "Wolfhampton";
    team[18].name = "Ipswitch";
    team[19].name = "Leiciter City";
    team[20].name = "South Nampton";

    team[1].ablity = 80;
    team[2].ablity = 75;
    team[3].ablity = 50;
    team[4].ablity = 60;
    team[5].ablity = 45;
    team[6].ablity = 48;
    team[7].ablity = 50;
    team[8].ablity = 50;
    team[9].ablity = 55;
    team[10].ablity = 45;
    team[11].ablity = 40;
    team[12].ablity = 43;
    team[13].ablity = 43;
    team[14].ablity = 41;
    team[15].ablity = 40;
    team[16].ablity = 35;
    team[17].ablity = 35;
    team[18].ablity = 30;
    team[19].ablity = 27;
    team[20].ablity = 25;

    for (int i = 1; i <= 20; i++) {
        team[i].train_remain = 5; // 初始化训练次数
    }

    for (int i = 1; i <= 20; i++) {
        cout << "(" << i << "):" << team[i].name << endl;
    }
    cout << "Choose your team:" << endl;
    cin >> cli_team;
    system("cls");

    if (cli_team <= 0 || cli_team > 20) {
        cout << "Input Error. Game Over";
        system("pause");
        return 0;
    }

    for (int i = 1; i <= 19 * 2; i++) {
        team[cli_team].train_remain = rand() % 6;
    laodazhouji:
        cout << "Round " << i << ": ";
        cout << "Your team: " << team[cli_team].name << endl;
        Sleep(500);
        cout << "Train remain: " << team[cli_team].train_remain << endl;
        Sleep(500);
        cout << "Your team ablity: " << team[cli_team].ablity << endl;
        Sleep(500);
        cout << "Begin Next Game" << endl;
        Sleep(500);
        cout << "Check the ranking board" << endl;
        Sleep(1000);
        cout << endl;
        cout << "(1): Train" << endl;
        cout << "(2): Check the ranking board" << endl;
        cout << "(3): Begin next game" << endl;
        int op;
        cin >> op;
        while (op < 1 || op > 3) {
            cout << "Input Error, please input it again ";
            Sleep(2000);
            system("cls");
            goto laodazhouji;
        }
        system("cls");
        if (op == 1) {
            if (team[cli_team].train_remain == 0) {
                cout << "There are no chance to train!" << endl;
                Sleep(2000);
                system("cls");
                goto laodazhouji;
            }
            team[cli_team].train_remain--;
            int win = rand() % 3;
            if (win == 1 || win == 2) {
                cout << "Train successfully! Team's ability +1!" << endl;
                Sleep(2000);
                team[cli_team].ablity++;
            } else {
                cout << "Train unsuccessfully! Team's ability -1!" << endl;
                Sleep(2000);
                team[cli_team].ablity--;
            }
            system("cls");
            goto laodazhouji;
        } else if (op == 2) {
            print_board();
            goto laodazhouji;
        } else if (op == 3) {
            play_game(i);
            play_others();
        }
    }

    system("cls");
    cout << "Season Over" << endl;
    Sleep(2000);
    cout << "This is the final table:" << endl;
    print_board();
    return 0;
}
原文