-
Notifications
You must be signed in to change notification settings - Fork 1
/
fichier.c
235 lines (226 loc) · 5.4 KB
/
fichier.c
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
#include "prototypes.h"
void affichageRegle()
{
FILE *regles = NULL;
regles = fopen("regles.txt", "r");
if(regles == NULL)
{
printf("erreur dans l'affichage des regles peut etre que le fichier regle est manquant.\n");
}
else
{
char chaineRegle[1000];
while(fgets(chaineRegle, 1000, regles) != NULL)
printf("%s", chaineRegle);
fclose(regles);
}
system("pause");
}
void sauvegardeScore(T_JOUEUR joueur[], int nombrejoueur)
{
FILE* score = NULL;
int i;
score = fopen("scores.txt", "a+");
if(score == NULL)
{
printf("erreur lors de la sauvegarde des scores peut etre que le fichier score est manquant.\n");
}
else
{
for(i = 0 ; i < nombrejoueur ; i++)
{
fprintf(score, "%s : %d\n", joueur[i].nom ,joueur[i].score);
}
fprintf(score, "\n");
fclose(score);
}
}
void afficherScore()
{
FILE *score = NULL;
score = fopen("scores.txt", "r");
if(score == NULL)
{
printf("erreur lors de l'ouverture des scores");
}
else
{
char chaineScore[10000];
system("cls");
while(fgets(chaineScore, 10000, score)!=NULL)
printf("%s", chaineScore);
fclose(score);
}
system("pause");
}
void selecteurSauvegarde(char *nomSauvegarde)
{
struct dirent *de;
DIR *dr = opendir("./sauvegarde");
char nomFichier[100][50];
int i=0,j = 0, y = 0, deplacement = 1, l,k=0;
system("cls");
if(dr == NULL)
{
printf("erreur d'ouverture de dossier");
exit(0);
}
while((de = readdir(dr)) !=NULL)
{
strcpy(nomFichier[i], de->d_name);
i++;
k++;
}
for(i=2;i<k;i++)
{
gotoligcol(j, 7);
printf("%s", nomFichier[i]);
j++;
}
gotoligcol(0,0);
printf("---->");
while(deplacement==1)
{
deplacerCurseurSauvegarde(&y, &deplacement, k);
printf("---->");
l = y+2;
}
strcat(nomSauvegarde, nomFichier[l]);
closedir(dr);
}
void deplacerCurseurSauvegarde(int *y, int *num, int k)
{
int c;
c = getch();
switch(c)
{
case 224:
{
c = getch();
switch(c)
{
case 72:
*y = *y-1;
gotoligcol(*y+1,0);
printf(" ");
break;
case 80:
*y = *y+1;
gotoligcol(*y-1,0);
printf(" ");
break;
}
break;
}
case 13: //0
*num = 0;
break;
}
if(*y == -1)
{
*y = 0;
}
else if(*y > k-3)
{
*y=*y-1;
}
gotoligcol(*y, 0);
}
void nomSauvegarde(char *nomSauvegarde)
{
char typeSauvegarde[5] = ".sav";
char sauvegardeTemp[50];
FILE *fichier = NULL;
printf("entrez le nom de votre sauvegarde\n");
fflush(stdin);
gets(sauvegardeTemp);
strcat(nomSauvegarde, sauvegardeTemp);
strcat(nomSauvegarde, typeSauvegarde);
fichier = fopen(nomSauvegarde, "w");
if(fichier == NULL)
{
printf("erreur lors de la creation de la sauvegarde");
}
}
void sauvegarderPartie(char *nomfichier, T_TUILE plateau[][27], int nombreJoueur, T_TUILE paquet[][6], T_JOUEUR *joueur, T_TUILE *pioche, int BS, int difficulte)
{
int i,j;
FILE *fichier = NULL;
fichier = fopen(nomfichier ,"w+");
fprintf(fichier, "%d\n%d\n%d\n", BS, nombreJoueur, difficulte);
for(i=0;i < nombreJoueur; i++)
{
for(j=0;j < 6 ; j++)
{
fprintf(fichier, "%c%d", paquet[i][j].forme, paquet[i][j].couleur);
}
}
for(i=0; i < BS; i++)
{
fprintf(fichier, "%c%d", pioche[i].forme, pioche[i].couleur);
}
for(i=0; i< 13;i++)
{
for(j=0; j < 27 ; j++)
{
fprintf(fichier, "%c%d", plateau[i][j].forme, plateau[i][j].couleur);
}
}
fprintf(fichier, "\n");
for(i=0; i < nombreJoueur; i++)
{
fprintf(fichier, "%d\n", strlen(joueur[i].nom));
}
for(i=0; i < nombreJoueur; i++)
{
fprintf(fichier, "%s%d\n", joueur[i].nom,joueur[i].score);
}
fclose(fichier);
}
void recupererSauvegarde(FILE *fichier, T_TUILE plateau[][27], int nombreJoueur, T_TUILE paquet[][6], T_JOUEUR *joueur, T_TUILE *pioche, int BS, int difficulte)
{
int i,j,temp[4];
system("cls");
for(i=0;i < nombreJoueur; i++)
{
for(j=0;j < 6;j++)
{
paquet[i][j].forme = fgetc(fichier);
fscanf(fichier, "%d", &paquet[i][j].couleur);
}
}
for(i=0;i < BS; i++)
{
pioche[i].forme = fgetc(fichier);
fscanf(fichier, "%d", &pioche[i].couleur);
}
for(i=0;i < 13;i++)
{
for(j=0;j < 27; j++)
{
plateau[i][j].forme = fgetc(fichier);
fscanf(fichier, "%d", &plateau[i][j].couleur);
}
}
fscanf(fichier, "\n");
for(i=0; i < nombreJoueur; i++)
{
fscanf(fichier, "%d", &temp[i]);
}
fscanf(fichier, "\n");
for(i=0; i < nombreJoueur; i++)
{
for(j=0; j < temp[i] ; j++)
{
joueur[i].nom[j] = fgetc(fichier);
}
if(i==0)
{
joueur[i].nom[temp[i]] = '\0';
}
joueur[i].nom[temp[i]+1] = '\0';
fscanf(fichier, " %d", &joueur[i].score);
fscanf(fichier, "\n");
}
effacerEcran();
}