-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
223 lines (200 loc) · 5.17 KB
/
menu.cpp
File metadata and controls
223 lines (200 loc) · 5.17 KB
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char teamNames[480]={};
char teamNamesandNums[32][25]={};
typedef struct players{
int number;
char name[20];
int age;
char nation[20];
char mainPost[2];
char tempPost[2];
int skill;
int form;
int fitness;
int goals;
int passGoals;
struct players *next;
}player_node;
typedef struct teams{
char teamName[15];
char group[2];
int state;
char confed[15];
int seed;
int pointOfteam;
int goalsRecev;
int goalsScoerds;
struct teams *next;
}teams_node;
////////////////var
char selectedTeam[25]={};
void loadPlayerInfo(player_node * headp);
void selectTeamsToManagement();
void pointsOfTeamsWrite(teams_node *headt);
void pointsOfTeamsRead(teams_node *head);
int main()
{
int menuOrder=0;
////////////this is main menu
printf("Choose one of these options :\n");
puts("1.a New WorldCup!");
puts("");
puts("2.load recent WorldCup");
scanf("%d",&menuOrder);
switch(menuOrder)
{
case 1: {///////reset the game and read info from files
selectTeamsToManagement();
break;}
case 2: {
//loadPlayerInfo(head);
//////////load all of recent WorldCup from files
break;
}
}
return 0;
}
void selectTeamsToManagement()
{
FILE *managment=fopen("teamNames.txt","r");
char line[801]={};
int team=0;
char teamNamesandNums[32][25]={};
int numTeams=1,i=0;
puts("Enter Number of your team that you want to manage");
while(numTeams<33)
{
fscanf(managment,"%s",teamNamesandNums[i]);
printf("%2d.%s\n",numTeams,teamNamesandNums[i]);
numTeams++;
i++;
}
fclose(managment);
managment=NULL;
while(1)
{
scanf("%d",&team);
if( team<33 && team>0)
{
break;
}
else
{
puts("choose team number from list!!");
}
}
printf("Your team is : %s", teamNamesandNums[team-1]);
strcpy(selectedTeam,teamNamesandNums[team-1]);
return;
}
void loadPlayerInfo(player_node * headp)
{
FILE *loadplayers = fopen("recentWorldCupPlayersInfo.txt","r");
if (!loadplayers)
{
puts("There is no recent WorldCup!!");
return;
}
char line[200]={};
int counter=0;
player_node *p=(player_node*)calloc(1,sizeof(player_node));
p=headp;
for(int i=0;fgets(line,200,loadplayers)!=NULL&&counter!=1005;i++)
{
int num;
char *namee=(char *)calloc (25,sizeof(char));
char *teamName=(char *)calloc (25,sizeof(char));
char *postt=(char *)calloc (1,sizeof(char));
char *postt_temp=(char *)calloc (1,sizeof(char));
int age,skill,form,fitness,goals,goalpass;
fscanf(loadplayers,"%d%s%d%s%s%s%d%d%d%d%d",&num,namee,&age,teamName,postt,postt_temp,&skill,&form,&fitness,&goals,&goalpass);
counter++;
/////////////file of players
p->number=num;
strcpy(p->name,namee);
strcpy(p->mainPost,postt);
strcpy(p->tempPost,postt_temp);
p->age=age;
strcpy(p->nation,teamName);
p->skill=skill;
p->form=form;
p->fitness=fitness;
p->goals=goals;
p->passGoals=goalpass;
////////////
p->next = (player_node *)calloc(1, sizeof(player_node));
p = p->next;
free(namee);
postt=NULL;
namee=NULL;
}
fclose(loadplayers);
loadplayers=NULL;
////////////////file of teams that the player wants to manage check!
///////////////file of points of teams in group games check!
///////////////file of goals and who and in which game is that
}
void pointsOfTeamsWrite(teams_node * head)
{
FILE *pointsOfTeams = fopen("TEAMSPOINTS.txt","w");
char *pointsOfTeamsInfo=(char *)calloc (350,sizeof(char));
teams_node *pt = (teams_node*)calloc(1,sizeof(teams_node));
pt = head;
while (pt != NULL) {
char integer_string[15]={};
sprintf(integer_string, "\n%d %d %d %s %s\n",pt->pointOfteam,pt->goalsRecev,pt->goalsScoerds,pt->teamName,pt->group );
strcat(pointsOfTeamsInfo, integer_string);
pt = pt->next;
}
fprintf(pointsOfTeams,"%s",pointsOfTeamsInfo);
fclose(pointsOfTeams);
pointsOfTeams=NULL;
}
void pointsOfTeamsRead(teams_node *head)
{
FILE *pointsOfTeams = fopen("TEAMSPOINTS.txt","r");
teams_node *pt = (teams_node*)calloc(1,sizeof(teams_node));
pt = head;
char line[20]={};
for(int i=0;fgets(line,20,pointsOfTeams)!=NULL;i++)
{
fscanf(pointsOfTeams,"%d %d %d %s %s",pt->pointOfteam,pt->goalsRecev,pt->goalsScoerds,pt->teamName,pt->group);
/////////////file of players
///////////
}
fclose(pointsOfTeams);
pointsOfTeams=NULL;
}
void playerGoalsWrite(player_node *headp,int isgroupGame,teams_node * headt,int )
{
///////////first var is : is groupGame?? 1 : 0
FILE *playersGoals = fopen("PlayersGoals.txt","w");
char *playersGoalsTXT=(char *)calloc (350,sizeof(char));
player_node *pp = (player_node*)calloc(1,sizeof(player_node));
teams_node *pt = (teams_node*)calloc(1,sizeof(teams_node));
pp = headp;
pt= headt;
int numTeams=0;
while (numTeams<33)
{
char * group = (char *)calloc(2,sizeof(char));
strcpy(group,pt->group);
while (strcmp(pt->teamName,pp->nation)==0) {
char integer_string[15]={};
//sprintf(integer_string, "\n%d %s %d %s %s\n",isgroupGame,group,);//////////what can i do for team? Vs team? ?????
strcat(playersGoalsTXT, integer_string);
pp = pp->next;
}
pt->next;
numTeams++;
}
fprintf(playersGoals,"%s",playersGoalsTXT);
fclose(playersGoals);
playersGoals=NULL;
}
void playerGoalsRead(player_node *headp)
{
/////namayesh dar jadval
}