-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.c
229 lines (208 loc) · 4.93 KB
/
load.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mesinkar.h"
#include "mesinkata.h"
#include "boolean.h"
#include "load.h"
#include "command.h"
#include "MatriksMap.h"
#include "unit.h"
#include "point.h"
#include "listdpUnit.h"
#include "player.h"
#include "jam.h"
void kataToString (Kata CKata, char *str)
/* I.S. CKata terdefinisi, str sembarang */
/* F.S. str terdefinisi dengan isi dari CKata.TabKata */
{ /* KAMUS LOKAL */
/* ALGORITMA */
strcpy(str, CKata.TabKata);
}
void kataToChar (Kata CKata, char *chr)
/* I.S. CKata terdefinisi, str sembarang */
/* F.S. str terdefinisi dengan isi dari CKata.TabKata */
{ /* ALGORITMA */
if (CKata.TabKata[0] == '_') {
*chr = ' ';
} else {
*chr = CKata.TabKata[0];
}
}
void kataToInt (Kata CKata, int *bil)
/* I.S. CKata terdefinisi, str sembarang */
/* F.S. str terdefinisi dengan isi dari CKata.TabKata */
{ /* KAMUS LOKAL */
/* ALGORITMA */
*bil = 0;
for (int i = 0; i < CKata.Length; ++i) {
*bil = (*bil) * 10 + CKata.TabKata[i] - '0';
}
}
/*** MEMBACA FILE EKSTERNAL ***/
void ReadTime(TANGGAL *T, JAM *J)
/* I.S. T dan J sembarang, CKata ada di kata pertama*/
/* F.S. Tanggal T dan Jam J terdefinisi */
{ /* KAMUS LOKAL */
/* ALGORITMA */
kataToInt(CKata, &Day(*T));
ADVKATA();
kataToInt(CKata, &Month(*T));
ADVKATA();
kataToInt(CKata, &Year(*T));
ADVKATA();
kataToInt(CKata, &Hour(*J));
ADVKATA();
kataToInt(CKata, &Minute(*J));
ADVKATA();
kataToInt(CKata, &Second(*J));
ADVKATA();
}
void ReadPoint (POINT *P)
/* I.S. P sembarang, CKata ada di kata pertama*/
/* F.S. Point P terdefinisi */
{ /* KAMUS LOKAL */
/* ALGORITMA */
kataToInt(CKata, &Absis(*P));
ADVKATA();
kataToInt(CKata, &Ordinat(*P));
ADVKATA();
}
void ReadUnit (Unit *U)
/* I.S. U sembarang, CKata ada di kata pertama*/
/* F.S. Unit U terdefinisi */
{ /* KAMUS LOKAL */
int CanAtk;
/* ALGORITMA */
kataToInt(CKata, &DamagePoints(*U));
ADVKATA();
kataToChar(CKata, &AttackType(*U));
ADVKATA();
kataToInt(CKata, &HealPoints(*U));
ADVKATA();
ReadPoint(&Locate(*U));
kataToInt(CKata, &HP(*U));
ADVKATA();
kataToChar(CKata, &Tipe(*U));
ADVKATA();
kataToInt(CKata, &MP(*U));
ADVKATA();
kataToInt(CKata, &Owner(*U));
ADVKATA();
kataToInt(CKata, &MaxHP(*U));
ADVKATA();
kataToInt(CKata, &MaxMP(*U));
ADVKATA();
kataToInt(CKata, &CanAtk);
CanAttack(*U) = (char) CanAtk;
ADVKATA();
}
void ReadBuild(Build *B)
/* I.S. B sembarang, CKata ada di kata pertama*/
/* F.S. Build B terdefinisi */
{ /* KAMUS LOKAL */
/* ALGORITMA */
kataToInt(CKata, &OwnerB(*B));
ADVKATA();
kataToChar(CKata, &TipeB(*B));
ADVKATA();
}
void ReadLocation(Location *L)
/* I.S. L sembarang, CKata ada di kata pertama*/
/* F.S. Location L terdefinisi */
{ /* ALGORITMA */
ReadBuild(&BuildIn(*L));
ReadUnit(&UnitIn(*L));
}
void ReadMatriksMap(MatriksMap *M)
/* I.S. file f sudah dibuka, MatriksMap M terdefinisi */
/* F.S. file f diisi dengan MatriksMap M */
{ /* KAMUS LOKAL */
int NBrs, NKol, i, j;
/* ALGORITMA */
kataToInt(CKata, &NBrs);
ADVKATA();
kataToInt(CKata, &NKol);
ADVKATA();
MakeMATRIKS(NBrs, NKol, M);
for (i = 1; i <= NBrsEff(*M); ++i) {
for (j = 1; j <= NKolEff(*M); ++j) {
ReadLocation(&Elmt(*M, i, j));
}
}
}
void ReadListOfPoint(List *L)
/* I.S. B sembarang, CKata ada di kata pertama*/
/* F.S. Build B terdefinisi */
{ /* KAMUS LOKAL */
POINT PTemp;
/* ALGORITMA */
CreateEmptyList(L);
while(strcmp(CKata.TabKata, "EndOfList")) {
ReadPoint(&PTemp);
InsVLast(L, PTemp);
}
ADVKATA();
}
void ReadPlayer(Player *P)
/* I.S. P sembarang, CKata ada di kata pertama*/
/* F.S. Player P terdefinisi */
{ /* KAMUS LOKAL */
/* ALGORITMA */
kataToInt(CKata, &PlayNumber(*P));
ADVKATA();
kataToInt(CKata, &PGold(*P));
ADVKATA();
ReadPoint(&CurrentUnitPos(*P));
kataToInt(CKata, &PIncome(*P));
ADVKATA();
kataToInt(CKata, &PUpKeep(*P));
ADVKATA();
ReadListOfPoint(&UnitList(*P));
ReadListOfPoint(&VillageList(*P));
for (int i = 1; i <= 4; ++i){
ReadPoint(&PlayerCastle(*P,i));
}
ReadPoint(&PlayerTower(*P));
}
void ReadTurn(Queue *Q)
/* I.S. Q sembarang, CKata ada di kata pertama*/
/* F.S. Queue Q terdefinisi */
{ /* KAMUS LOKAL */
int playertemp;
/* ALGORITMA */
CreateEmptyQ(Q,2);
while(strcmp(CKata.TabKata, "EndOfQueue")) {
kataToInt(CKata, &playertemp);
AddQ(Q, playertemp);
ADVKATA();
}
ADVKATA();
}
void Load(MatriksMap *MatMap, Player *Player1, Player *Player2, Queue *Turn)
/* Melakukan load file */
/* I.S. file pitakar.txt berisi hasil save, semua parameter tidak terdefinisi*/
/* F.S. mendefinisikan semua parameter */
{ /* KAMUS LOKAL */
TANGGAL T;
JAM J;
char filename[256];
/* ALGORITMA */
printf("Enter your filename (<filename.txt>)\n");
scanf("%s", filename);
printf("Loading file '%s' ...\n", filename);
STARTKATA(filename);
ReadTime(&T, &J);
ReadMatriksMap(MatMap);
ReadPlayer(Player1);
ReadPlayer(Player2);
ReadTurn(Turn);
while (!EndKata) {
ADVKATA();
}
printf("File from ");
TulisTANGGAL(T);
printf(" ");
TulisJAM(J);
printf(" successfully loaded.\n");
}