【官方】英超模拟器V1.0.2
GeorgeDeng · · 休闲·娱乐
c++小游戏:英超模拟器V1.0.2上线!
注:此游戏非商业用途。
V1.0.2 来咯!
更新了:
-
加入了金钱系统,未来可能在这里更新。
-
完善了旁观者模式。
-
将能力值随机数增大。
exe下载,密码durb。
Game Code:
#include <iostream>
#include <cstdio>
#include <ctime>
#include <random>
#include <windows.h>
#include <algorithm>
#include <iomanip> // 用于格式化输出
using namespace std;
int vis[25]; // 全局 vis 数组
struct node {
string name;
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;
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(10) << "Points"
<< setw(10) << "Goals"
<< setw(10) << "Lose"
<< setw(10) << "GD" << endl;
for (int i = 1; i <= 20; i++) {
cout << left << setw(5) << i
<< setw(20) << temp_team[i].name
<< setw(10) << temp_team[i].point
<< setw(10) << temp_team[i].goal
<< setw(10) << temp_team[i].lose
<< setw(10) << (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;
team[cli_team].money+=my_points-you_points;
cout<<endl<<"You win youself "<<my_points-you_points<<" M€!"<<endl;
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;
cout<<endl<<"You win youself "<<0<<" M€!"<<endl;
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;
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;
}
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;
team[cli_team].money+=my_points-you_points;
cout<<endl<<"You win youself "<<my_points-you_points<<" M€!"<<endl;
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;
cout<<endl<<"You win youself "<<0<<" M€!"<<endl;
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;
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;
}
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;
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;
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;
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;
}
}
}
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;
Sleep(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;
}
Sleep(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:
system("cls");
cout << "Round " << i << endl;
Sleep(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) {
system("cls");
print_board();
goto laodazhouji;
}
if (op == 1) {
system("cls");
print_ablity();
system("pause");
goto laodazhouji;
}
if (op == 2) {
system("cls");
watcher_play_game(local_vis, i);
system("pause");
}
}
// 释放内存
for (int i = 0; i < 205; i++) {
delete[] local_vis[i];
}
delete[] local_vis;
system("cls");
cout << "Season Over" << endl;
Sleep(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;
Sleep(2000);
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 = "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;
system("cls");
if (cli_team <= 0 || cli_team > 21) {
cout << "Input Error. Game Over";
system("pause");
return 0;
}
if(cli_team==21){
char ch;
//cout<<"Not avliable now!"<<endl;
//system("pause");
//system("cls");
//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;
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(500);
cout << "Check the money" <<endl;
Sleep(500);
cout << "Buy chance to train your team" <<endl;
Sleep(1000);
cout << endl;
cout << "(1): Train" << endl;
cout << "(2): Check the ranking board" << endl;
cout << "(3): Begin next game" << endl;
cout<<"(4): Check the money"<<endl;
cout<<"(5): Buy chance to train your team"<<endl;
int op;
cin >> op;
while (op < 1 || op > 6) {
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() % 2;
if (win == 1) {
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();
}else if(op==4){
system("cls");
cout<<"You have "<<team[cli_team].money<<" M€"<<endl;
system("pause");
system("cls");
goto laodazhouji;
}else if(op==5){
system("cls");
money:
system("cls");
cout<<"(1)2M€-->2 chances"<<endl;
cout<<"(2)3M€-->5 chances"<<endl;
cout<<"(3)10M€-->12 chances"<<endl;
cout<<"(4)2M€-->1 chances"<<endl;
cout<<"(5)1M€-->1 chances"<<endl;
cout<<"(6)3M€-->4 chances"<<endl;
cout<<"(7)5M€-->7 chances"<<endl;
cout<<"(8)8M€-->8 chances"<<endl;
cout<<"(9)10M€-->10 chances"<<endl;
cout<<"(10)20M€-->40 chances"<<endl;
cout<<"(11) exit"<<endl;
int cli_op;
cin>>cli_op;
if(cli_op==11){
system("cls");
goto laodazhouji;
}
if(cli_op<1||cli_op>10){
cout<<"Input error";
Sleep(2000);
goto money;
}else if(cli_op==1){
if(team[cli_team].money<2){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=2;
team[cli_team].train_remain+=2;
}else if(cli_op==2){
if(team[cli_team].money<3){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=3;
team[cli_team].train_remain+=5;
}else if(cli_op==3){
if(team[cli_team].money<10){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=10;
team[cli_team].train_remain+=12;
}else if(cli_op==4){
if(team[cli_team].money<2){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=2;
team[cli_team].train_remain+=1;
}else if(cli_op==5){
if(team[cli_team].money<1){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=1;
team[cli_team].train_remain+=1;
}else if(cli_op==6){
if(team[cli_team].money<3){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=3;
team[cli_team].train_remain+=4;
}else if(cli_op==7){
if(team[cli_team].money<5){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=5;
team[cli_team].train_remain+=7;
}else if(cli_op==8){
if(team[cli_team].money<8){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=8;
team[cli_team].train_remain+=8;
}else if(cli_op==9){
if(team[cli_team].money<10){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=10;
team[cli_team].train_remain+=10;
}else if(cli_op==10){
if(team[cli_team].money<20){
cout<<"You can't buy this!"<<endl;
Sleep(2000);
goto money;
}
cout<<"OK!"<<endl;
team[cli_team].money-=20;
team[cli_team].train_remain+=40;
}
Sleep(2000);
system("cls");
goto laodazhouji;
}
}
system("cls");
cout << "Season Over" << endl;
Sleep(2000);
cout << "This is the final table:" << endl;
print_board();
return 0;
}