-
Notifications
You must be signed in to change notification settings - Fork 1
/
savemanager.c
78 lines (59 loc) · 1.47 KB
/
savemanager.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
#include "SaveManager.h"
#include "Util.h"
#include "Pokemon.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void saveTeam(pokemon_t** pokeTeam, char* fileName)
{
FILE *saveFile;
// open file for appending
saveFile = fopen (fileName, "a");
if (saveFile == NULL)
{
fprintf(stderr, "\nERROR OPENING SAVE FILE TO SAVE!\n");
exit (1);
}
for(int i = 0; i < MAXTEAMSIZE; ++i)
{
if(pokeTeam[i] != NULL)
{
savePokemon(pokeTeam[i], saveFile);
}
}
// close file
fclose (saveFile);
}
pokemon_t** loadTeam(char* fileName)
{
pokemon_t** pokeTeam;
int i = 0;
pokeTeam = (pokemon_t**) malloc (sizeof(pokemon_t*)*MAXTEAMSIZE);
FILE *saveFile;
// open file for appending
saveFile = fopen (fileName, "r");
if (saveFile == NULL)
{
fprintf(stderr, "\nERROR OPENING SAVE FILE TO SAVE!\n");
exit (1);
}
do
{
pokeTeam[i++] = loadPokemon(saveFile);
} while(pokeTeam[i-1] != NULL && (i < MAXTEAMSIZE));
for(;i < MAXTEAMSIZE;++i)
pokeTeam[i] = NULL;
// close file
fclose (saveFile);
return pokeTeam;
}
unsigned char* makeCryptoMon(pokemon_t* pokemon)
{
int size = sizeof(pokemon_t);
unsigned char* cryptomon;
cryptomon = (unsigned char*) malloc(sizeof(pokemon_t));
memcpy(cryptomon, pokemon, size);
for(int i = 0; i < size; ++i)
cryptomon[i] = cryptomon[i]^200;
return cryptomon;
}