-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileHanabi.c
107 lines (90 loc) · 2.51 KB
/
FileHanabi.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
#include <stdio.h>
#include <stdlib.h>
#include "Globais.h"
#include "lab.h"
//--------------------------------------------------------------
//function that save the game in hard disk
int saveGame(char *fileName)
{
FILE *fp;
fp=fopen(fileName,"w");
if(fp==NULL)
return false;
fprintf(fp,"HANABI FILE GAME\n"); //signature that indicates an HANABI file game
fprintf(fp,"%s\n",name);
fprintf(fp,"%d\n",playing);
for(i=0;i<50;i++)
fprintf(fp,"%d ",deck[i]);
fprintf(fp,"\n");
fprintf(fp,"%d\n",inTopCard);
for(i=0;i<5;i++)
fprintf(fp,"%d ",player[i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",bot[i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",table[i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",botInfo[0][i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",botInfo[1][i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",playerInfo[0][i]);
fprintf(fp,"\n");
for(i=0;i<5;i++)
fprintf(fp,"%d ",playerInfo[1][i]);
fprintf(fp,"\n");
fprintf(fp,"%d\n%d\n",life,clues);
for(i=0;i<5;i++)
{for(k=0;k<5;k++)
fprintf(fp,"%d ",discard[i][k]);
fprintf(fp,"\n");
}
fprintf(fp,"%s",status);
fclose(fp);
return true;
}
//--------------------------------------------------------------
//function that read from file the game HANABI saved
int loadGame(char *fileName)
{
FILE *fp;
char aux[20];
fp=fopen(fileName,"r");
if(fp==NULL)
return false;
fgets(aux,20,fp);
if(strcmp(aux,"HANABI FILE GAME\n")!=0) //cheks if has a HANABI file signature
return false;
fgets(name,16,fp);
fscanf(fp,"%d\n",&playing);
for(i=0;i<50;i++)
fscanf(fp,"%d ",&deck[i]);
fscanf(fp,"%d\n",&inTopCard);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&player[i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&bot[i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&table[i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&botInfo[0][i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&botInfo[1][i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&playerInfo[0][i]);
for(i=0;i<5;i++)
fscanf(fp,"%d ",&playerInfo[1][i]);
fscanf(fp,"%d\n%d\n",&life,&clues);
for(i=0;i<5;i++)
{for(k=0;k<5;k++)
fscanf(fp,"%d ",&discard[i][k]);
}
fgets(status,30,fp);
fclose(fp);
return true;
}