-
Notifications
You must be signed in to change notification settings - Fork 0
/
savegame.h
87 lines (78 loc) · 2.56 KB
/
savegame.h
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
#ifndef SAVEGAME_H_INCLUDED
#define SAVEGAME_H_INCLUDED
#include "highscore.h"
# include "variables.h"
#include<string.h>
struct savegame
{
char savename[100]; //saves user name
int savescore; //saves user's score
int savegamestate; //saves game state
int savenamestate; //checks that whether the name is inputted or not
int savethorx;
int savethory;
int savethorlifeindex;
int savesuperpowerindex;
int savea;
int saveb; //to save big frosts
int savekeyindex;
int savesmallfrostx1;
int savesmallfrosty1;
int savesmallfrostx2;
int savesmallfrosty2;
savegame()
{
}
//save game constructor
savegame(char *main_savename, int main_savescore, int main_savegamestate, int main_savenamestate, int main_savethorx, int main_savethory, int main_savethorlifeindex,int main_savesuperpowerindex,int main_savea,int main_saveb,int main_savekeyindex,int main_savesmallfrostx1,int main_savesmallfrosty1,int main_savesmallfrostx2,int main_savesmallfrosty2)
{
strcpy(savename, main_savename);
savescore = main_savescore;
savegamestate = main_savegamestate;
savenamestate = main_savenamestate;
savethorx = main_savethorx;
savethory = main_savethory;
savethorlifeindex = main_savethorlifeindex;
savesuperpowerindex = main_savesuperpowerindex;
savea = main_savea;
saveb = main_saveb;
savekeyindex = main_savekeyindex;
savesmallfrostx1 = main_savesmallfrostx1;
savesmallfrosty1 = main_savesmallfrosty1;
savesmallfrostx2 = main_savesmallfrostx2;
savesmallfrosty2 = main_savesmallfrosty2;
}
};
void savethegame()
{
savegame s(playername, playerscore, gamestate, namestate,thorx,thory,thorlifeindex,superpowerindex,a,b,keyindex,smallfrostx1, smallfrosty1, smallfrostx2,smallfrosty2);
FILE *sg;
sg = fopen("save game.bin", "wb"); // save game.bin file opens in write mode
fwrite(&s, sizeof(s), 1, sg);
fclose(sg);
}
void loadthegame()
{
savegame sv;
FILE *lg;
lg = fopen("save game.bin", "rb"); // save game.bin file opens in read mode
fread(&sv, sizeof(sv), 1, lg);
//assigns value to continue the game
namestate = sv.savenamestate;
gamestate = sv.savegamestate;
playerscore = sv.savescore;
strcpy(playername, sv.savename);
thorx = sv.savethorx;
thory = sv.savethory;
thorlifeindex = sv.savethorlifeindex;
superpowerindex = sv.savesuperpowerindex;
a = sv.savea;
b = sv.saveb;
keyindex = sv.savekeyindex;
smallfrostx1 = sv.savesmallfrostx1;
smallfrosty1 = sv.savesmallfrosty1;
smallfrostx2 = sv.savesmallfrostx2;
smallfrosty2 = sv.savesmallfrosty2;
fclose(lg);
}
#endif