跳到正文

休闲·娱乐

Upd 【官方】英超小游戏V1.0.3

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

文章信息

发布
2026年2月26日
收录
2026年5月14日
更新
2026年11月8日
篇幅
约 42 分钟

版本

  1. v2当前
  2. v1

for linux

C++
// #include <iostream>
// #include <cstdlib>
// #define int long long
// #define endl '\n'
// using namespace std;

// signed main()
// {
//     ios::sync_with_stdio(false);
//     cin.tie(0),cout.tie(0);
//     cout<<"114514";
//     // system("clear");
//     cout<<"\033[2J\033[1;1H";
//     cout<<"cleared";
//     return 0;
// }
/*
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <random>
#include <algorithm>
#include <iomanip>
#include <thread>
#include <chrono>
using namespace std;

void clearScreen(){
    cout<<"\033[2J\033[1;1H";
}
void SSSleep(int millis){
    std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <random>
#include <algorithm>
#include <iomanip>
#include <thread>
#include <chrono>
#include <termios.h>
#include <unistd.h>
using namespace std;

void clearScreen(){
    std::cout << "\033[2J\033[3J\033[1;1H";
}
void SSSleep(int millis){
    std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
void pressAnyKeyToContinue() {
    std::cout << "Press any key to continue...";
    std::cout.flush();

    // 保存当前终端属性
    struct termios old_tio, new_tio;
    tcgetattr(STDIN_FILENO, &old_tio);
    new_tio = old_tio;

    // 修改:禁用规范模式(ICANON)和回显(ECHO)
    new_tio.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);

    // 读取一个字符
    getchar();

    // 恢复原始终端属性
    tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
    cout<<"\n";
}
int vis[25]; // 全局 vis 数组
struct node {
    string name;
    int win;
    int draw;
    int lost;
    int ablity;
    int point;
    int goal, lose;
    int train_remain;
    int money;
} 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;
    if (a.win != b.win) return a.win > b.win;
    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);

    // 使用 setw 设置场宽
    cout << left << setw(5) << "Rank"
         << setw(20) << "Team"
         << setw(6) << "Wins"
         << setw(6) << "Draws"
         << setw(6) << "Losts"
         << setw(7) << "Goals"
         << setw(7) << "Lose"
         << setw(6) << "Points"
         << setw(7) << "GD" << endl;

    for (int i = 1; i <= 20; i++) {
        cout << left << setw(5) << i
             << setw(20) << temp_team[i].name
             << setw(6) << temp_team[i].win
             << setw(6) << temp_team[i].draw
             << setw(6) << temp_team[i].lost
             << setw(7) << temp_team[i].goal
             << setw(7) << temp_team[i].lose
             << setw(6) << temp_team[i].point
             << setw(7) << (temp_team[i].goal - temp_team[i].lose);

        if (temp_team[i].name == team[cli_team].name) {
            cout << " (My team)";
        }
        cout << endl;
    }
    pressAnyKeyToContinue();
    clearScreen();
}

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;
        pressAnyKeyToContinue();
        int result = rand() % (team[cli_team].ablity + team[oponment].ablity);
        if (result < team[cli_team].ablity) {
            cout << "You win by ";
            int my_points = rand() % 7;
            while (my_points == 0) my_points = rand() % 7;
            int you_points = rand() % 3;
            while (you_points >= my_points) {
                you_points = rand() % 3;
            }
            team[cli_team].win++;
            team[oponment].lost++;
            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;
            team[cli_team].money+=my_points-you_points;
            cout<<endl<<"You win youself "<<my_points-you_points<<" M€!"<<endl;
            pressAnyKeyToContinue();
            clearScreen();
        } else if (result == team[cli_team].ablity) {
            cout << "You draw by ";
            int my_points = rand() % 7;
            team[cli_team].draw++;
            team[oponment].draw++;
            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;
            cout<<endl<<"You win youself "<<0<<" M€!"<<endl;
            pressAnyKeyToContinue();
            clearScreen();
        } else {
            cout << "You lose by ";
            int my_points = rand() % 7;
            while (my_points == 0) my_points = rand() % 7;
            int you_points = rand() % 3;
            while (you_points >= my_points) {
                you_points = rand() % 3;
            }
            team[cli_team].lost++;
            team[oponment].win++;
            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;
            if(team[cli_team].money>=0-(my_points-you_points)){
            	cout<<endl<<"You lose youself "<<0-(my_points-you_points)<<" M€!"<<endl;
            	team[cli_team].money+=my_points-you_points;
			}
            pressAnyKeyToContinue();
            clearScreen();
        }
    } 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;
        pressAnyKeyToContinue();
        int result = rand() % (team[cli_team].ablity + team[oponment].ablity);
        if (result < team[cli_team].ablity) {
            team[cli_team].win++;
            team[oponment].lost++;
            cout << "You win by ";
            int my_points = rand() % 7;
            while (my_points == 0) my_points = rand() % 10;
            int you_points = rand() % 3;
            while (you_points >= my_points) {
                you_points = rand() % 3;
            }
            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;
            team[cli_team].money+=my_points-you_points;
            cout<<endl<<"You win youself "<<my_points-you_points<<" M€!"<<endl;
            pressAnyKeyToContinue();
            clearScreen();
        } else if (result == team[cli_team].ablity) {
            cout << "You draw by ";
            team[cli_team].draw++;
            team[oponment].draw++;
            int my_points = rand() % 7;
            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;
            cout<<endl<<"You win youself "<<0<<" M€!"<<endl;
            pressAnyKeyToContinue();
            clearScreen();
        } else {
            team[cli_team].lost++;
            team[oponment].win++;
            cout << "You lose by ";
            int my_points = rand() % 7;
            while (my_points == 0) my_points = rand() % 7;
            int you_points = rand() % 3;
            while (you_points >= my_points) {
                you_points = rand() % 3;
            }
            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;
            if(team[cli_team].money>=0-(my_points-you_points)){
            	cout<<endl<<"You lose youself "<<0-(my_points-you_points)<<" M€!"<<endl;
            	team[cli_team].money+=my_points-you_points;
			}
            pressAnyKeyToContinue();
            clearScreen();
        }
    }
}

void play_others() {
    bool local_vis[21] = {false}; // 将数组大小增加到 21,避免越界
    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;
        int local_result = rand() % (team[i].ablity + team[opn].ablity);
        if (local_result < team[i].ablity) {
            team[i].win++;
            team[opn].lost++;
            team[i].point += 3;
            int add1 = rand() % 7 + 1;
            int add2 = rand() % add1;
            team[i].goal += add1, team[i].lose += add2;
            team[opn].goal += add2, team[opn].lose += add1;
        } else if (local_result == team[i].ablity) {
            team[i].draw++;
            team[opn].draw++;
            team[i].point += 1;
            team[opn].point += 1;
            int add1 = rand() % 7 + 1;
            int add2 = add1;
            team[i].goal += add1, team[i].lose += add2;
            team[opn].goal += add2, team[opn].lose += add1;
        } else {
            team[opn].win++;
            team[i].lost++;
            team[opn].point += 3;
            int add1 = rand() % 7 + 1;
            int add2 = rand() % add1;
            team[i].goal += add2, team[i].lose += add1;
            team[opn].goal += add1, team[opn].lose += add2;
        }
    }
}

void print_ablity() {
    cout << left << setw(20) << "Team_name" << setw(10) << "Team_ablity" << endl;
    for (int i = 1; i <= 20; i++) {
        cout << left << setw(20) << team[i].name << setw(10) << team[i].ablity << endl;
    }
}

void watcher_play_game(int **local_vis2, int round) {
    bool local_vis[205] = {false}; // 初始化 local_vis 数组
    if (round <= 19) {
        for (int i = 1; i <= 20; i++) {
            if (local_vis[i]) continue;
            local_vis[i] = true;
            int opn = rand() % 20 + 1;
            while (local_vis[opn] || local_vis2[i][opn] == 1) {
                opn = rand() % 20 + 1;
            }
            local_vis[opn] = true;
            local_vis2[i][opn]++, local_vis2[opn][i]++;
            cout << team[i].name << " vs. " << team[opn].name << endl;
            SSSleep(500);
            int local_result = rand() % (team[i].ablity + team[opn].ablity);
            if (local_result < team[i].ablity) {
                team[i].point += 3;
                int add1 = rand() % 10 + 1;
                int add2 = rand() % add1;
                cout << team[i].name << ' ' << add1 << " - " << add2 << ' ' << team[opn].name << endl;
                team[i].goal += add1, team[i].lose += add2;
                team[opn].goal += add2, team[opn].lose += add1;
            } else if (local_result == team[i].ablity) {
                team[i].point += 1;
                team[opn].point += 1;
                int add1 = rand() % 10 + 1;
                int add2 = add1;
                cout << team[i].name << ' ' << add1 << " - " << add2 << ' ' << team[opn].name << endl;
                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;
                cout << team[i].name << ' ' << add2 << " - " << add1 << ' ' << team[opn].name << endl;
                team[i].goal += add2, team[i].lose += add1;
                team[opn].goal += add1, team[opn].lose += add2;
            }
            SSSleep(500);
        }
    }
    if (round > 19) {
        for (int i = 1; i <= 20; i++) {
            if (local_vis[i]) continue;
            local_vis[i] = true;
            int opn = rand() % 20 + 1;
            while (local_vis[opn] || local_vis2[i][opn] == 1) {
                opn = rand() % 20 + 1;
            }
            local_vis[opn] = true;
            local_vis2[i][opn]++, local_vis2[opn][i]++;
            cout << team[i].name << " vs. " << team[opn].name << endl;
            int local_result = rand() % (team[i].ablity + team[opn].ablity);
            if (local_result < team[i].ablity) {
                team[i].point += 3;
                int add1 = rand() % 10 + 1;
                int add2 = rand() % add1;
                cout << team[i].name << ' ' << add1 << " - " << add2 << ' ' << team[opn].name << endl;
                team[i].goal += add1, team[i].lose += add2;
                team[opn].goal += add2, team[opn].lose += add1;
            } else if (local_result == team[i].ablity) {
                team[i].point += 1;
                team[opn].point += 1;
                int add1 = rand() % 10 + 1;
                int add2 = add1;
                cout << team[i].name << ' ' << add1 << " - " << add2 << ' ' << team[opn].name << endl;
                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;
                cout << team[i].name << ' ' << add2 << " - " << add1 << ' ' << team[opn].name << endl;
                team[i].goal += add2, team[i].lose += add1;
                team[opn].goal += add1, team[opn].lose += add2;
            }
        }
    }
}

void watcher() {
    int **local_vis = new int*[205];
    for (int i = 0; i < 205; i++) {
        local_vis[i] = new int[205]();
    }

    for (int i = 1; i <= 19 * 2; i++) {
    laodazhouji:
        clearScreen();
        cout << "Round " << i << endl;
        SSSleep(500);
        int op;
        cout << "(1) Check all teams' ablity" << endl;
        cout << "(2) Check This round's draw & begin this round's match" << endl;
        cout << "(3) Check ranking board" << endl;
        cout << "(4) exit" << endl;
        cin >> op;
        if (op == 4) {
            // 释放内存
            for (int i = 0; i < 205; i++) {
                delete[] local_vis[i];
            }
            delete[] local_vis;
            return;
        }
        if (op == 3) {
            clearScreen();
            print_board();
            goto laodazhouji;
        }
        if (op == 1) {
            clearScreen();
            print_ablity();
            pressAnyKeyToContinue();
            goto laodazhouji;
        }
        if (op == 2) {
            clearScreen();
            watcher_play_game(local_vis, i);
            pressAnyKeyToContinue();
        }
    }

    // 释放内存
    for (int i = 0; i < 205; i++) {
        delete[] local_vis[i];
    }
    delete[] local_vis;
    clearScreen();
    cout << "Season Over" << endl;
    SSSleep(2000);
    cout << "This is the final table:" << endl;
    print_board();
}

int main() {
	start:
    srand(time(NULL));
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << "Premier League" << endl;
    SSSleep(2000);
    clearScreen();

    // 初始化球队
    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 = "Bournemouth";
    team[11].name = "Brighton";
    team[12].name = "Fulham";
    team[13].name = "Brentford";
    team[14].name = "Crystal Palace";
    team[15].name = "West Ham United";
    team[16].name = "Everton";
    team[17].name = "Wolverhampton";
    team[18].name = "Ipswich";
    team[19].name = "Leicester City";
    team[20].name = "Southampton";

    team[1].ablity = rand() % 101;
    team[2].ablity = rand() % 95;
    team[3].ablity = rand() % 90;
    team[4].ablity = rand() % 87;
    team[5].ablity = rand() % 77;
    team[6].ablity = rand() % 75;
    team[7].ablity = rand() % 75;
    team[8].ablity = rand() %73;
    team[9].ablity = rand()%70;
    team[10].ablity = rand()%68;
    team[11].ablity = rand()%68;
    team[12].ablity = rand()%67;
    team[13].ablity = rand()%69;
    team[14].ablity = rand()%65;
    team[15].ablity = rand()%65;
    team[16].ablity = rand()%63;
    team[17].ablity = rand()%60;
    team[18].ablity = rand()%55;
    team[19].ablity = rand()%52;
    team[20].ablity = rand()%50;

    for (int i = 1; i <= 20; i++) {
        cout << "(" << i << "):" << team[i].name << endl;
    }
    cout << "Choose your team:(21 Watcher mode, but may get a dead cycle)" << endl;
    cin >> cli_team;
    clearScreen();

    if (cli_team <= 0 || cli_team > 21) {
        cout << "Input Error. Game Over";
        pressAnyKeyToContinue();
        return 0;
    }
    if(cli_team==21){
    	char ch;
    	cout<<"Not avliable now!"<<endl;
    	pressAnyKeyToContinue();
    	clearScreen();
    	goto start;
    	watcher();
    	return 0;
	}
	team[cli_team].train_remain = rand()%6;
    for (int i = 1; i <= 19 * 2; i++) {
    laodazhouji:
        cout << "Round " << i << ": " << endl;
        cout << "Your team: " << team[cli_team].name << endl;
        SSSleep(500);
        cout << "Train remain: " << team[cli_team].train_remain << endl;
        SSSleep(500);
        cout << "Your team ablity: " << team[cli_team].ablity << endl;
        SSSleep(500);
        cout<<"Your money: "<<team[cli_team].money<<" M€"<<endl;
        SSSleep(500);
        cout << "Begin Next Game" << endl;
        SSSleep(500);
        cout << "Check the ranking board" << endl;
        SSSleep(500);
        cout << "Buy chance to train your team" <<endl;
        SSSleep(1000);
        cout << endl;
        cout << "(1): Train" << endl;
        cout << "(2): Check the ranking board" << endl;
        cout << "(3): Begin next game" << endl;
        cout<<"(4): Buy chance to train your team"<<endl;
        int op;
        cin >> op;
        while (op < 1 || op > 6) {
            cout << "Input Error, please input it again ";
            SSSleep(2000);
            clearScreen();
            goto laodazhouji;
        }
        clearScreen();
        if (op == 1) {
            if (team[cli_team].train_remain == 0) {
                cout << "There are no chance to train!" << endl;
                SSSleep(2000);
                clearScreen();
                goto laodazhouji;
            }
            team[cli_team].train_remain--;
            int win = rand() % 2;
            if (win == 1) {
                cout << "Train successfully! Team's ability +1!" << endl;
                SSSleep(2000);
                team[cli_team].ablity++;
            } else {
                cout << "Train unsuccessfully! Team's ability -1!" << endl;
                SSSleep(2000);
                team[cli_team].ablity--;
            }
            clearScreen();
            goto laodazhouji;
        } else if (op == 2) {
            print_board();
            goto laodazhouji;
        } else if (op == 3) {
            play_game(i);
            play_others();
        }else if(op==4){
			clearScreen();
				money:
				clearScreen();
				cout<<"You have "<<team[cli_team].money <<" M€"<<endl;
				int money[11],chance[11];
				for(int i = 1;i<=10;i++){
					money[i] = rand()%20+1,chance[i] = rand()%30+1;
					cout<<"("<<i<<"): "<<money[i]<<"M€ ---> "<<chance[i]<<" chances."<<endl;
				}
				cout<<"(11) exit"<<endl;
				int cli_op;
				cin>>cli_op;
				if(cli_op==11){
					clearScreen();
					goto laodazhouji;
				}
				if(cli_op<1||cli_op>10){
					cout<<"Input error";
					SSSleep(2000);
					goto money;
				}else{
					if(team[cli_team].money>=money[cli_op]){
						cout<<"Deal!"<<endl;
						SSSleep(2000);
						team[cli_team].money-=money[cli_op];
						team[cli_team].train_remain+=chance[cli_op];
					}else{
						cout<<"You can't buy it!"<<endl;
						SSSleep(2000);
						goto money;
					}
				}
				SSSleep(2000);
			clearScreen();
			goto laodazhouji;
		}
    }
    clearScreen();
    cout << "The season is over" << endl;
    SSSleep(2000);
    cout << "This is the final table:" << endl;
    print_board();
    return 0;
}
原文