英超小游戏V1.1-deepseek版
这篇小游戏非官方,作者为了测试 deepseek 的能力而测试出来的。
#include <iostream>
#include <cstdio>
#include <ctime>
#include <random>
#include <windows.h>
#include <algorithm>
#include <vector>
using namespace std;
int vis[25]; // 全局 vis 数组
struct Player {
string name;
int ability;
string position; // 位置:前锋、中场、后卫、门将
bool is_injured; // 是否受伤
};
struct Team {
string name;
int ablity;
int point;
int goal, lose;
int train_remain;
vector<Player> players; // 球队的球员列表
} team[25];
int cli_team = 0; // 玩家选择的球队
int oponment; // 对手球队
bool cmp(Team a, Team 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() {
Team 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 << "排名 球队名称 积分 进球 失球" << 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 << "(我的球队)";
}
cout << endl;
}
system("pause");
system("cls");
}
void random_event() {
int event = rand() % 5;
if (event == 0) {
cout << "糟糕!你的主力球员受伤了,能力值暂时下降!" << endl;
team[cli_team].ablity -= 2;
} else if (event == 1) {
cout << "球迷们非常支持你的球队,士气高涨!能力值暂时提升!" << endl;
team[cli_team].ablity += 2;
} else if (event == 2) {
cout << "天气恶劣,比赛受到影响,双方能力值下降!" << endl;
team[cli_team].ablity -= 1;
team[oponment].ablity -= 1;
}
}
void choose_tactic() {
cout << "选择战术:" << endl;
cout << "(1): 进攻" << endl;
cout << "(2): 防守" << endl;
cout << "(3): 平衡" << endl;
int tactic;
cin >> tactic;
if (tactic == 1) {
cout << "你选择了进攻战术,进球概率增加,但失球风险也增加!" << endl;
team[cli_team].ablity += 3;
} else if (tactic == 2) {
cout << "你选择了防守战术,失球概率降低,但进球机会减少!" << endl;
team[cli_team].ablity -= 2;
} else {
cout << "你选择了平衡战术,攻守兼备!" << endl;
}
}
void play_game(int round) {
choose_tactic(); // 选择战术
random_event(); // 随机事件
if (round <= 19) {
oponment = rand() % 20 + 1;
while (vis[oponment] == 1 || oponment == cli_team) {
oponment = rand() % 20 + 1;
}
vis[oponment]++;
cout << "你的对手是: " << team[oponment].name << endl;
system("pause");
int result = rand() % (team[cli_team].ablity + team[oponment].ablity);
if (result < team[cli_team].ablity) {
cout << "你赢了,比分是 ";
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;
} else if (result == team[cli_team].ablity) {
cout << "你打平了,比分是 ";
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;
} else {
cout << "你输了,比分是 ";
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 << "英超联赛模拟器" << endl;
Sleep(200);
system("cls");
// 初始化球队
team[1].name = "利物浦";
team[2].name = "阿森纳";
team[3].name = "阿斯顿维拉";
team[4].name = "曼城";
team[5].name = "曼联";
team[6].name = "热刺";
team[7].name = "纽卡斯尔联";
team[8].name = "切尔西";
team[9].name = "诺丁汉森林";
team[10].name = "伯恩茅斯";
team[11].name = "布莱顿";
team[12].name = "富勒姆";
team[13].name = "布伦特福德";
team[14].name = "水晶宫";
team[15].name = "西汉姆联";
team[16].name = "埃弗顿";
team[17].name = "狼队";
team[18].name = "伊普斯维奇";
team[19].name = "莱斯特城";
team[20].name = "南安普顿";
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 << "选择你的球队:" << endl;
cin >> cli_team;
system("cls");
if (cli_team <= 0 || cli_team > 20) {
cout << "输入错误,游戏结束";
system("pause");
return 0;
}
for (int i = 1; i <= 19 * 2; i++) {
team[cli_team].train_remain = rand() % 6;
laodazhouji:
cout << "第 " << i << " 轮: ";
cout << "你的球队: " << team[cli_team].name << endl;
Sleep(500);
cout << "剩余训练次数: " << team[cli_team].train_remain << endl;
Sleep(500);
cout << "你的球队能力值: " << team[cli_team].ablity << endl;
Sleep(500);
cout << "开始下一场比赛" << endl;
Sleep(500);
cout << "查看排行榜" << endl;
Sleep(1000);
cout << endl;
cout << "(1): 训练" << endl;
cout << "(2): 查看排行榜" << endl;
cout << "(3): 开始下一场比赛" << endl;
int op;
cin >> op;
while (op < 1 || op > 3) {
cout << "输入错误,请重新输入 ";
Sleep(2000);
system("cls");
goto laodazhouji;
}
system("cls");
if (op == 1) {
if (team[cli_team].train_remain == 0) {
cout << "没有训练次数了!" << endl;
Sleep(2000);
system("cls");
goto laodazhouji;
}
team[cli_team].train_remain--;
int win = rand() % 3;
if (win == 1 || win == 2) {
cout << "训练成功!球队能力值 +1!" << endl;
Sleep(2000);
team[cli_team].ablity++;
} else {
cout << "训练失败!球队能力值 -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 << "赛季结束" << endl;
Sleep(2000);
cout << "这是最终排行榜:" << endl;
print_board();
return 0;
}