forked from efe3535/Virtual-League
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1058 lines (919 loc) · 33.8 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define underline "\033[4m"
#define ununderline "\033[0m"
// ------------------ player.h ------------------
class Player{
private:
string firstName, lastName;
int age;
char position;
int performance;
int jesusNumber;
public:
Player(const string& firstName, const string& lastName, const char& position);
void SetPlayerAge(const int& a);
void SetPlayerJesusNumber(const int& jesusNumber);
void SetPlayerPerformance(const int& performance);
string GetPlayerName() const;
char GetPlayerPosition() const;
int GetPlayerAge() const;
int GetPlayerPerformance() const;
int GetPlayerJesusNumber() const;
};
// ------------------ coach.h ------------------
class Coach{
private:
string firstName, lastName;
public:
Coach(const string& firstName, const string& lastName);
string GetCoachName() const;
};
class Team{
private:
string teamName;
char shortName[3];
Coach* coach;
int defence, midfielder, striker;
vector<Player*> player;
int averageAge, averagePerformance;
int averagePerformanceDefence, averagePerformanceMidfielder, averagePerformanceStriker;
int played = 0, won = 0, draw = 0, lost = 0, goal = 0, against = 0, goalDifference = 0, point = 0;
public:
Team(const string& teamName, Coach* coach);
void SetShortName(const string& teamName);
void AddPlayer(const char& position);
void SetTactic(const int& defence, const int& midfielder, const int& striker);
void SetMatchResult(const int& goal, const int& against);
string GetTeamName() const;
string GetShortName() const;
string GetCoach() const;
int GetTeamAverageAge() const;
int GetTeamAveragePerformance() const;
int GetTeamPlayed() const;
int GetTeamWon() const;
int GetTeamDraw() const;
int GetTeamLost() const;
int GetTeamGoal() const;
int GetTeamAgainst() const;
int GetTeamGoalDifference() const;
int GetTeamPoint() const;
int GetAveragePerformancePosition(const char& p);
void GetTeamInfo(const int& state) const;
void GetPlayersName() const;
Player* GetPlayer(const int& index);
};
// ------------------ match.h ------------------
class Match{
private:
int id = 0;
Team* home;
Team* away;
bool played = false;
int homeGoal = 0;
int awayGoal = 0;
public:
Match(Team* home, Team* away);
void SetMatchId(const int& id);
int GetMatchID() const;
Team* GetMatchHomeTeam() const;
Team* GetMatchAwayTeam() const;
bool GetPlayed() const;
int GetMatchHomeGoal() const;
int GetMatchAwayGoal() const;
void GetMatchInfo(const int& round, const int& match) const;
void CalcMatchResult(Team* home, Team* away);
void MatchResult(Team* home, const int& homeGoal, Team* away, const int& awayGoal);
};
// ------------------ main.h ------------------
vector<Team*> teams;
vector<string*> shortNames;
vector<string> playerFirstNames, playerLastNames;
vector<vector<Match*>> matchs;
vector<vector<Match*>> season1_matchs;
vector<vector<Match*>> season2_matchs;
int teamPlayer = 11;
int season = 0;
int totalRounds = 0; // weeks
int matchesPerRound = 0; // matchs
int minPerformance = 30, maxPerformance = 100;
int averageMinPerformance = 60, averageMaxPerformance = 100;
int terminalWidth = 162;
void CreateTeam(const string& teamName, const string& coachFirstName, const string& coachLastName);
void LoadTeamInfo(const string& fileName);
void LoadPlayerInfo(const string& fileName, vector<string>& listName);
void RandomFixture();
void RandomMatch();
void SetAllMatchIdThenSeasons();
void StartFixture(const int& season);
void CalcMatchResultWithSeason(vector<vector<Match*>> array);
Team* SelectTeam();
Player* SelectPlayer(Team* team, const int& menuStateForBack);
void GetTeamsName();
void GetMatchWithTeam(Team* team);
void GetAllMatch();
void GetMatchInfoWithID(const int& id);
void Sort(const string& type);
void Scoreboard();
void MenuProcess(const int& value);
void Back(const int& state);
void Menu();
int RandomNumber(const int& minValue, const int& maxValue);
void Repeat(const char& character, const int& repeatTime);
void Title(const string& title);
char Position(const char& position);
int DecreaseNumber(int number);
int WrongValue(const int& minValue, const int& maxValue, const string& warningText, const string& tryAgainText);
string StringLeftAlignment(string str, const int& maxCharacter, const int& pointNumber);
// ------------------ player.cpp ------------------
Player::Player(const string& fN, const string& lN, const char& p){
firstName = fN;
lastName = lN;
position = p;
}
void Player::SetPlayerAge(const int& a){
age = a;
}
void Player::SetPlayerPerformance(const int& pm){
performance = pm;
}
void Player::SetPlayerJesusNumber(const int& jN){
jesusNumber = jN;
}
string Player::GetPlayerName() const{
return firstName + " " + lastName;
}
char Player::GetPlayerPosition() const{
return position;
}
int Player::GetPlayerAge() const{
return age;
}
int Player::GetPlayerPerformance() const{
return performance;
}
int Player::GetPlayerJesusNumber() const{
return jesusNumber;
}
// ------------------ coach.cpp ------------------
Coach::Coach(const string& fN, const string& lN){
firstName = fN;
lastName = lN;
}
string Coach::GetCoachName() const{
return firstName + " " + lastName;
}
// ------------------ team.cpp ------------------
Team::Team(const string& tN, Coach* c){
teamName = tN;
coach = c;
SetShortName(tN);
SetTactic(4, 4, 2);
}
void Team::SetShortName(const string& tN){
// First Character
shortName[0] = tN[0];
// Second Character
int space = tN.find(" ");
if (space > 0){
shortName[1] = tN[space+1];
}
else{
shortName[1] = tN[1];
}
// Third Character
string* temp;
temp += shortName[0] + shortName[1];
if(find(shortNames.begin(), shortNames.end(), temp) != shortNames.end()){
if (space > 0){
shortName[2] = tN[space+2];
}
else{
shortName[2] = tN[2];
}
temp += shortName[2];
}
else{
shortName[2] = '\0';
}
shortName[1] = toupper(shortName[1]);
shortName[2] = toupper(shortName[2]);
shortNames.push_back(temp);
}
void Team::AddPlayer(const char& po){
string randomFirstName = playerFirstNames[RandomNumber(0, playerFirstNames.size() - 1)];
string randomLastName = playerLastNames[RandomNumber(0, playerLastNames.size() - 1)];
Player* p = new Player(randomFirstName, randomLastName, po);
player.push_back(p);
}
void Team::SetTactic(const int& d, const int& m, const int& s){
if (d + m + s != 10){
cout << "Taktikteki oyuncu sayýsýnýn toplamý 10 olmalýdýr. (Örn: 4-4-2)" << endl;
}
else {
// Goalkeeper
AddPlayer('G');
// Defence
for (int i = 1; i <= d; i++){
AddPlayer('D');
}
// Midfielder
for (int i = 1; i <= m; i++){
AddPlayer('M');
}
// Striker
for (int i = 1; i <= s; i++){
AddPlayer('S');
}
int minAge = 18, maxAge = 36;
int averageMinAge = 25, averageMaxAge = 32;
do{
averageAge = 0;
int totalAge = 0;
for (int i = 0; i < player.size(); i++){
player[i]->SetPlayerAge(RandomNumber(minAge, maxAge));
totalAge += player[i]->GetPlayerAge();
}
averageAge += totalAge / player.size();
} while (!(averageAge >= averageMinAge && averageAge <= averageMaxAge));
do{
averagePerformance = 0;
int totalPerformance = 0;
for (int i = 0; i < player.size(); i++){
player[i]->SetPlayerPerformance(RandomNumber(minPerformance, maxPerformance));
totalPerformance += player[i]->GetPlayerPerformance();
}
averagePerformance += totalPerformance / player.size();
} while(!(averagePerformance >= averageMinPerformance && averagePerformance <= averageMaxPerformance));
int minJesusNumber = 1, maxJesusNumber = 99;
bool alreadyHave = false;
int randomNumber;
for (int i = 0; i < player.size(); i++){
randomNumber = RandomNumber(minJesusNumber, maxJesusNumber);
while(alreadyHave == false){
for (int j = 0; j < player.size(); j++){
if (player[j]->GetPlayerJesusNumber() == randomNumber)
alreadyHave = true;
}
if (alreadyHave == false)
break;
else
randomNumber = RandomNumber(minJesusNumber, maxJesusNumber);
}
player[i]->SetPlayerJesusNumber(randomNumber);
}
}
}
void Team::SetMatchResult(const int& g, const int& a){
if (g > a){
won++;
point += 3;
}
else if (g == a){
draw++;
point += 1;
}
else {
lost++;
point += 0;
}
played++;
goal += g;
against += a;
goalDifference += g - a;
}
string Team::GetTeamName() const{
return teamName;
}
string Team::GetShortName() const{
return shortName;
}
string Team::GetCoach() const{
return coach->GetCoachName();
}
int Team::GetTeamAverageAge() const{
int total = 0;
for (int i = 0; i < player.size(); i++){
Player* p = player[i];
total += p->GetPlayerAge();
}
return total / player.size();
}
int Team::GetTeamAveragePerformance() const{
int total = 0;
for (int i = 0; i < player.size(); i++){
Player* p = player[i];
total += p->GetPlayerPerformance();
}
return total / player.size();
}
int Team::GetTeamPlayed() const{
return played;
}
int Team::GetTeamWon() const{
return won;
}
int Team::GetTeamDraw() const{
return draw;
}
int Team::GetTeamLost() const{
return lost;
}
int Team::GetTeamGoal() const{
return goal;
}
int Team::GetTeamAgainst() const{
return against;
}
int Team::GetTeamGoalDifference() const{
return goalDifference;
}
int Team::GetTeamPoint() const{
return point;
}
int Team::GetAveragePerformancePosition(const char& p){
int total = 0, number = 0;
for (int i = 0; i < player.size(); i++){
if (player[i]->GetPlayerPosition() == p){
total += player[i]->GetPlayerPerformance();
number += 1;
}
}
return total / number;
}
void Team::GetTeamInfo(const int& s) const{
Title(GetTeamName() + " | " + GetShortName() + " | " + GetCoach() + " | Ortalama Performans: " + to_string(GetTeamAveragePerformance()) + " | Ortalama Yaþ: " + to_string(GetTeamAverageAge()) + " | Galibiyet: " + to_string(GetTeamWon()) + " | Yenilgi: " + to_string(GetTeamLost()) + " | Atýlan Gol: " + to_string(GetTeamGoal()) + " | Yenilen Gol: " + to_string(GetTeamAgainst()) + " | Averaj: " + to_string(GetTeamGoalDifference()));
cout << endl;
cout << string(36, ' ') << underline << " Sýra No " << ununderline << " "<< underline << " Ýsim Soyisim " << ununderline << " " << underline << " Mevki " << ununderline << " " << underline << " Yaþ " << ununderline << " " << underline << " Performans " << ununderline << " " << underline " Forma Numarasý " << ununderline << endl;
for (int i = 0; i < player.size(); i++){
Player* p = player[i];
string playerName = p->GetPlayerName();
int showMaximumCharacterInPlayerName = 19;
int pointNumber = 3;
if (playerName.size() < showMaximumCharacterInPlayerName){
for (int j = playerName.size(); j < showMaximumCharacterInPlayerName - 1; j++){
playerName += ' ';
}
}
else{
for (int j = showMaximumCharacterInPlayerName - pointNumber - 1; j < showMaximumCharacterInPlayerName - 1; j++){
playerName[j] = '.';
for (int k = showMaximumCharacterInPlayerName - 1; k < playerName.size(); k++){
playerName[k] = '\0';
}
}
}
cout << string(36, ' ') << " " << setw(2) << i+1 << " " << playerName << " " << Position(p->GetPlayerPosition()) << " " << setw(2) << p->GetPlayerAge() << " " << setw(3) << p->GetPlayerPerformance() << " " << setw(2) << p->GetPlayerJesusNumber() << endl;
}
cout << endl;
cout << "1. Oyuncu Performansýný Düzenle " << endl;
cout << endl;
cout << "0. Geri Dön" << endl;
cout << endl;
cout << "Lütfen yapmak istediðiniz iþlem numarasýný giriniz: ";
int state = WrongValue(0, 1, "Hatalý iþlem numarasý girdiniz.", "Lütfen tekrar giriniz: ");
switch(state){
case 0: {
MenuProcess(s);
break;
}
case 1: {
cout << endl;
cout << "Lütfen performansýný deðiþtirmek istediðiniz oyuncunun sýra numarasýný giriniz: ";
int no = WrongValue(1, 11, "Hatalý oyuncu sýra numarasý girdiniz.", "Lütfen oyuncu sýra numarasý tekrar giriniz: ");
Player* p = player[no-1];
cout << endl;
cout << "Lütfen güncellemek istediðiniz yeni performans deðerini giriniz: ";
int newPerf = WrongValue(30, 100, "Oyuncu performansý 30 ile 100 arasýnda olmalýdýr.", "Lütfen oyuncu performans deðerini tekrar giriniz: ");
p->SetPlayerPerformance(newPerf);
GetTeamInfo(s);
}
}
}
void Team::GetPlayersName() const{
cout << endl;
for (int i = 0; i < player.size(); i++){
string empty = "";
if (i < 9)
empty = " ";
cout << empty << i+1 << ". " << setw(24) << player[i]->GetPlayerName() << " | " << setw(3) <<player[i]->GetPlayerPerformance() << " |" << endl;
}
cout << endl;
}
Player* Team::GetPlayer(const int& index){
return player[index];
}
// ------------------ match.cpp ------------------
Match::Match(Team* h, Team* a){
home = h;
away = a;
}
void Match::SetMatchId(const int& i){
id = i;
}
int Match::GetMatchID() const{
return id;
}
Team* Match::GetMatchHomeTeam() const{
return home;
}
Team* Match::GetMatchAwayTeam() const{
return away;
}
bool Match::GetPlayed() const{
return played;
}
int Match::GetMatchHomeGoal() const{
return homeGoal;
}
int Match::GetMatchAwayGoal() const{
return awayGoal;
}
void Match::GetMatchInfo(const int& round, const int& match) const{
cout << endl;
string emptyf = "", emptys = "", emptyt = "";
if (id <= 9){
emptyf = " ";
}
if (id <= 99){
emptyf += " ";
}
if (round < 9){
emptys = " ";
}
if (match < 9){
emptyt = " ";
}
string winHomeS, winHomeE, winAwayS, winAwayE;
if (homeGoal > awayGoal){
winHomeS += underline;
winHomeE += ununderline;
}
else if (awayGoal > homeGoal){
winAwayS += underline;
winAwayE += ununderline;
}
if (played == 0){
cout << "ID: " << emptyf << id << " | " << emptys << round + 1 << ". Hafta " << emptyt << match + 1 << ". Maç:" << setw(24) << home->GetTeamName() << " - " << away->GetTeamName() << endl;
}
else
{
cout << "ID: " << emptyf << id << " | " << emptys << round + 1 << ". Hafta " << emptyt << match + 1 << ". Maç:" << setw(24) << home->GetTeamName() << " " << winHomeS << homeGoal << winHomeE << " - " << winAwayS << awayGoal << winAwayE << " " << away->GetTeamName() << endl;
}
}
void Match::CalcMatchResult(Team* home, Team* away){
int homeGoalValue = RandomNumber(0, 6);
int awayGoalValue = RandomNumber(0, 6);
if (home->GetAveragePerformancePosition('S') > away->GetAveragePerformancePosition('S')){
homeGoalValue++;
}
else if (away->GetAveragePerformancePosition('S') > home->GetAveragePerformancePosition('S')){
awayGoalValue++;
}
if (home->GetAveragePerformancePosition('D') > away->GetAveragePerformancePosition('D')){
DecreaseNumber(awayGoalValue);
}
else if (away->GetAveragePerformancePosition('D') > home->GetAveragePerformancePosition('D')){
DecreaseNumber(homeGoalValue);
}
if (home->GetAveragePerformancePosition('M') > away->GetAveragePerformancePosition('M')){
homeGoalValue++;
DecreaseNumber(awayGoalValue);
}
else if (away->GetAveragePerformancePosition('M') > home->GetAveragePerformancePosition('M')){
awayGoalValue++;
DecreaseNumber(homeGoalValue);
}
if(home->GetTeamAveragePerformance() > away->GetTeamAveragePerformance()){
int random = RandomNumber(0, 1);
if (random == 0)
homeGoalValue++;
else
DecreaseNumber(awayGoalValue);
}
else if(away->GetTeamAveragePerformance() > home->GetTeamAveragePerformance()){
int random = RandomNumber(0, 1);
if (random == 0)
awayGoalValue++;
else
DecreaseNumber(homeGoalValue);
}
MatchResult(home, homeGoalValue, away, awayGoalValue);
}
void Match::MatchResult(Team* home, const int& hG, Team* away, const int& aG){
home->SetMatchResult(hG, aG);
away->SetMatchResult(aG, hG);
homeGoal = hG;
awayGoal = aG;
played = 1;
}
// ------------------ main.cpp ------------------
void CreateTeam(const string& tN, const string& cFN, const string& cLN){
Coach* c = new Coach(cFN, cLN);
Team* t = new Team(tN, c);
teams.push_back(t);
}
void LoadTeamInfo(const string& fN){
string line, teamName, coachName, coachFirstName, coachLastName;
ifstream file(fN);
if (file.is_open()){
while (getline(file, line)){
int reagent = line.find('-');
teamName = line.substr(0, reagent - 1);
string coachName = line.substr(reagent + 2, line.length());
int space = coachName.find(' ');
string coachFirstName = coachName.substr(0, space);
string coachLastName = coachName.substr(space + 1, coachName.length());
CreateTeam(teamName, coachFirstName, coachLastName);
}
file.close();
}
}
void LoadPlayerInfo(const string& fN, vector<string>& list){
string line;
ifstream file(fN);
if (file.is_open()){
while(getline(file, line)){
list.push_back(line);
}
file.close();
}
}
void RandomFixture(){
totalRounds = teams.size() - 1;
matchesPerRound = teams.size() / 2;
for (int round = 0; round < totalRounds; round++) {
vector<Match*> season1_rounds;
vector<Match*> season2_rounds;
for (int match = 0; match < matchesPerRound; match++) {
int home = (round + match) % (teams.size() - 1);
int away = (teams.size() - 1 - match + round) % (teams.size() - 1);
if (match == 0) {
away = teams.size() - 1;
}
Match* m1 = new Match(teams[home], teams[away]);
Match* m2 = new Match(teams[away], teams[home]);
season1_rounds.push_back(m1);
season2_rounds.push_back(m2);
}
season1_matchs.push_back(season1_rounds);
season2_matchs.push_back(season2_rounds);
}
RandomMatch();
SetAllMatchIdThenSeasons();
}
void RandomMatch(){
for (int i = 0; i < season1_matchs.size(); i++) {
int r = i + rand() % (season1_matchs.size() - i);
swap(season1_matchs[i], season1_matchs[r]);
}
for (int round = 0; round < totalRounds; round++) {
vector<Match*> rounds;
for (int match = 0; match < matchesPerRound; match++) {
rounds.push_back(season1_matchs[round][match]);
}
matchs.push_back(rounds);
}
for (int i = 0; i < season2_matchs.size(); i++) {
int r = i + rand() % (season2_matchs.size() - i);
swap(season2_matchs[i], season2_matchs[r]);
}
for (int round = 0; round < totalRounds; round++) {
vector<Match*> rounds;
for (int match = 0; match < matchesPerRound; match++) {
rounds.push_back(season2_matchs[round][match]);
}
matchs.push_back(rounds);
}
}
void SetAllMatchIdThenSeasons(){
int id = 1;
for (int round = 0; round < totalRounds*2; round++) {
for (int match = 0; match < matchesPerRound; match++) {
Match* m = matchs[round][match];
m->SetMatchId(id);
id++;
}
}
}
void StartFixture(const int& s){
if (s == 0){
CalcMatchResultWithSeason(season1_matchs);
season++;
}
else if (s == 1){
CalcMatchResultWithSeason(season2_matchs);
season++;
}
}
void CalcMatchResultWithSeason(vector<vector<Match*>> array){
for (int round = 0; round < totalRounds; round++){
for (int match = 0; match < matchesPerRound; match++) {
Match* m = array[round][match];
Team* home = m->GetMatchHomeTeam();
Team* away = m->GetMatchAwayTeam();
m->CalcMatchResult(home, away);
}
}
}
Team* SelectTeam(){
GetTeamsName();
cout << "0. Menüye Dön" << endl;
cout << endl;
cout << "Lütfen iþlem yapmak istediðiniz takým numarasýný giriniz: ";
int teamIndex = WrongValue(0, teams.size(), "Hatalý takým numarasý girdiniz.", "Lütfen tekrar giriniz: ");
if (teamIndex == 0)
Menu();
Team* t = teams[teamIndex-1];
return t;
}
Player* SelectPlayer(Team* t, const int& s){
t->GetPlayersName();
cout << "0. Geri Dön" << endl;
cout << endl;
cout << "Lütfen iþlem yapmak istediðiniz oyuncu numarasýný giriniz: ";
int playerIndex = WrongValue(0, 11, "Hatalý oyuncu numarasý girdiniz.", "Lütfen tekrar giriniz: ");
if (playerIndex == 0)
MenuProcess(s);
cout << endl;
return t->GetPlayer(playerIndex-1);
}
void GetTeamsName(){
cout << endl;
for (int i = 0; i < teams.size(); i++){
string teamName = StringLeftAlignment(teams[i]->GetTeamName(), 16, 3);
cout << setw(2) << i+1 << ". " << teamName << " | " << teams[i]->GetShortName() << endl;
}
cout << endl;
}
void GetMatchWithTeam(Team* t){
int totalRounds = (teams.size() - 1) * (season == 0 ? 1 : season);
int matchesPerRound = teams.size() / 2;
for (int round = 0; round < totalRounds; round++) {
for (int match = 0; match < matchesPerRound; match++) {
if((matchs[round][match]->GetMatchHomeTeam() == t) || (matchs[round][match]->GetMatchAwayTeam() == t)){
matchs[round][match]->GetMatchInfo(round, match);
}
}
}
cout << endl;
}
void GetAllMatch(){
int totalRounds = (teams.size() - 1) * (season == 0 ? 1 : season);
int matchesPerRound = teams.size() / 2;
for (int round = 0; round < totalRounds; round++) {
for (int match = 0; match < matchesPerRound; match++) {
matchs[round][match]->GetMatchInfo(round, match);
}
}
cout << endl;
cout << "0. Geri Dön" << endl;
cout << endl;
cout << "Lütfen görmek istediðiniz karþýlaþmanýn Maç ID'sini giriniz veya geri dönebilirsiniz: ";
int id = WrongValue(0, totalRounds * matchesPerRound, "Hatalý Maç ID'si girdiniz.", "Lütfen tekrar giriniz: ");
if (id == 0)
Menu();
cout << endl;
GetMatchInfoWithID(id);
}
void GetMatchInfoWithID(const int& id){
int totalRounds = (teams.size() - 1) * (season == 0 ? 1 : season);
int matchesPerRound = teams.size() / 2;
for (int round = 0; round < totalRounds; round++) {
for (int match = 0; match < matchesPerRound; match++) {
if(matchs[round][match]->GetMatchID() == id){
Team* home = matchs[round][match]->GetMatchHomeTeam();
Team* away = matchs[round][match]->GetMatchAwayTeam();
int HomeAveragePerformance = 0;
int AwayAveragePerformance = 0;
stringstream ss0, ss1;
ss0 << home->GetTeamAveragePerformance();
ss0 >> HomeAveragePerformance;
ss1 << away->GetTeamAveragePerformance();
ss1 >> AwayAveragePerformance;
int totalAverage = home->GetTeamAveragePerformance() + away->GetTeamAveragePerformance();
int homeWin = (home->GetTeamAveragePerformance() * 100) / totalAverage;
int awayWin = (away->GetTeamAveragePerformance() * 100) / totalAverage;
cout << setw(20) << underline << " " << home->GetTeamName() << " | " << home->GetShortName() << " | " << home->GetTeamAveragePerformance() << " | %" << homeWin << " " << ununderline << setw(22) << underline << " " << away->GetTeamName() << " | " << away->GetShortName() << " | " << away->GetTeamAveragePerformance() << " | " << "%" << awayWin << " " << ununderline << endl;
cout << endl;
for (int i = 0; i < teamPlayer; i++){
Player* hP = home->GetPlayer(i);
Player* aP = away->GetPlayer(i);
string homeTeamPlayerName = hP->GetPlayerName();
string awayTeamPlayerName = aP->GetPlayerName();
char homeTeamPlayerPosition = hP->GetPlayerPosition();
char awayTeamPlayerPosition = aP->GetPlayerPosition();
int homeTeamPlayerPerformance = hP->GetPlayerPerformance();
int awayTeamPlayerPerformance = aP->GetPlayerPerformance();
string empty = "";
if (i < 9){
empty = " ";
}
cout << empty << i+1 << ". " << setw(30) << homeTeamPlayerName << " | " << Position(homeTeamPlayerPosition) << " | " << homeTeamPlayerPerformance << setw(44) << awayTeamPlayerName << " | " << Position(awayTeamPlayerPosition) << " | " << awayTeamPlayerPerformance << endl;
}
if (matchs[round][match]->GetPlayed()){
cout << "--------------------------------------------------------------------------------------------------------------" << endl;
cout << setw(43) << "Atýlan Gol: " << matchs[round][match]->GetMatchHomeGoal() << setw(52) << "Atýlan Gol: " << matchs[round][match]->GetMatchAwayGoal() << endl;
}
else
cout << endl;
}
}
}
}
void Sort(const string& t){
for (int i = 0; i < teams.size()-1; i++){
Team* temp;
for (int j = 0; j < teams.size()-1; j++){
bool state;
if (t == "Point"){
state = teams[j]->GetTeamPoint() < teams[j+1]->GetTeamPoint();
}
else if (t == "Average"){
state = teams[j]->GetTeamPoint() == teams[j+1]->GetTeamPoint() && teams[j]->GetTeamGoalDifference() < teams[j+1]->GetTeamGoalDifference();
}
else if (t == "MostGoal"){
state = teams[j]->GetTeamPoint() == teams[j+1]->GetTeamPoint() && teams[j]->GetTeamGoalDifference() == teams[j+1]->GetTeamGoalDifference() && teams[j]->GetTeamGoal() < teams[j+1]->GetTeamGoal();
}
else{
state = teams[j]->GetTeamName() > teams[j+1]->GetTeamName();
}
if(state){
temp = teams[j];
teams[j] = teams[j+1];
teams[j+1] = temp;
}
}
}
}
void Scoreboard(){
cout << endl;
if (season == 0){
Sort("Alphabetical");
}
Sort("Point");
Sort("Average");
Sort("MostGoal");
cout << underline << " Sýra No " << ununderline << " " << underline << " Takým Adý " << ununderline << " " << underline << " Oynadýðý Maç " << ununderline << " " << underline << " Galibiyet Sayýsý " << ununderline << " " << underline " Beraberlik Sayýsý " << ununderline << " " << underline << " Maðlubiyet Sayýsý " << ununderline << " " << underline << " Atýlan Gol " << ununderline << " " << underline << " Yenilen Gol " << ununderline << " " << underline " Averaj " << ununderline << " " << underline " Puan " << ununderline << endl;
for (int i = 0; i < teams.size(); i++){
Team* t = teams[i];
string teamName = t->GetTeamName();
int showMaximumCharacterInTeamName = 16;
int pointNumber = 3;
if (teamName.size() < showMaximumCharacterInTeamName){
for (int j = teamName.size(); j < showMaximumCharacterInTeamName - 1; j++){
teamName += ' ';
}
}
else{
for (int j = showMaximumCharacterInTeamName - pointNumber - 1; j < showMaximumCharacterInTeamName - 1; j++){
teamName[j] = '.';
for (int k = showMaximumCharacterInTeamName - 1; k < teamName.size(); k++){
teamName[k] = '\0';
}
}
}
cout << " " << setw(2) << i+1 << " " << teamName << " " << setw(2) << t->GetTeamPlayed() << " " << setw(2) << t->GetTeamWon() << " " << setw(2) << t->GetTeamDraw() << " " << setw(2) << t->GetTeamLost() << " " << setw(3) << t->GetTeamGoal() << " " << setw(3) << t->GetTeamAgainst() << " " << setw(3) << t->GetTeamGoalDifference() << " " << setw(3) << t->GetTeamPoint() << endl;
}
}
void MenuProcess(const int& s){
switch (s){
case 1: {
Team* t = SelectTeam();
t->GetTeamInfo(s);
break;
}
case 2: {
GetMatchWithTeam(SelectTeam());
Back(s);
break;
}
case 3: {
GetAllMatch();
Back(s);
break;
}
case 4: {
StartFixture(season);
Menu();
}
case 0: {
exit(s);
break;
}
}
}
void Back(const int& s){
cout << "0. Geri Dön: ";
int back = WrongValue(0, 0, "Hatalý iþlem numarasý girdiniz.", "Lütfen tekrar giriniz: ");
if (back == 0){
MenuProcess(s);
}
}
void Menu(){
Title("Sanal Lig - Puan Durumu");
Scoreboard();
cout << endl;
cout << "1. Takým Bilgisini Göster" << endl;
cout << "2. Takýmýn Haftalýk Maçlarýný Göster" << endl;
cout << "3. Maç ID'si Ýle Detaylý Karþýlaþma Bilgisini Göster" << endl;
if (season == 0){
cout << "4. Ýlk Sezonu Oynat" << endl;
}
else if (season == 1){
cout << "4. Ýkinci Sezonu Oynat" << endl;
}
cout << endl;
cout << "0. Çýkýþ" << endl;
cout << endl;
cout << "Lütfen yapmak istediðiniz iþlem numarasýný giriniz: ";
int state = WrongValue(0, 4, "Hatalý iþlem numarasý girdiniz.", "Lütfen tekrar giriniz: ");
MenuProcess(state);
}
int RandomNumber(const int& min, const int& max){
return rand() % (max - min + 1) + min;
}
void Repeat(const char& c, const int& r){
for (int i = 0; i < r; i++){
cout << c;
}
}
void Title(const string& t){
cout << endl;
Repeat('-', terminalWidth);
cout << endl;
Repeat(' ', (terminalWidth - t.size()) / 2);
cout << t << endl;
Repeat('-', terminalWidth);
cout << endl;
}
char Position(const char& position){
char p;
switch (position){
case 'G':
p = 'K';
break;
case 'D':
p = 'D';
break;