-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_fill.cpp
281 lines (270 loc) · 7.11 KB
/
block_fill.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "block_fill.h"
#include <fstream>
#include <string>
// content = color * 100 + property
// overall property = property(*10 + direction (if any))
// overall_property of a portal:
// serial = overall_property / 10
// direction = overall % 10
/*
fill the content
input:
· int variable overall property
· pointer pointing to int array content[5][10]
· int variable state indicating inner or outer
· int array, storing a randonly generated portal colors
no return value
*/
void fill(int overall, int *cont, int state, int portal_color[]) {
const int row = 5;
const int col = 10;
const int grdwid = 1, grdlen = 10;
const int perwid = 4, perlen = 4;
const int elfinwid = 4, elfinlen = 2;
const int polwid1 = 2, pollen1 = 10;
const int polwid2 = 2, pollen2 = 5;
const int gatwid = 4, gatlen = 4;
int *ct = cont;
int GRD_C = 231;
int AIR_C = 0;
if (state == 1) {
int temp;
temp = GRD_C;
GRD_C = AIR_C;
AIR_C = temp;
}
int ELFIN_H = 4;
int ELFIN_W = 6;
//load the pre-saved template
std::ifstream model1 ("./lib/blocks/1.txt");
std::string temp1;
std::string temp10;
std::ifstream model3 ("./lib/blocks/3.txt");
std::string temp3;
std::ifstream model4 ("./lib/blocks/4.txt");
std::string temp4;
std::ifstream model51 ("./lib/blocks/51.txt");
std::string temp51;
std::ifstream model52 ("./lib/blocks/52.txt");
std::string temp52;
std::ifstream model61 ("./lib/blocks/61.txt");
std::string temp61;
std::ifstream model62 ("./lib/blocks/62.txt");
std::string temp62;
std::ifstream model63 ("./lib/blocks/63.txt");
std::string temp63;
std::ifstream model64 ("./lib/blocks/64.txt");
std::string temp64;
if (overall / 10 >= 6) { //portal
int direct = overall % 10;
int serial = overall / 10;
int numcolor = GRD_C;
int color_arr[8] = {9, 219, 93, 12, 14, 118, 226, 214};
numcolor = color_arr[portal_color[serial - 6]];
/*switch (serial) {
case 6:
numcolor = 9; //red
break;
case 7:
numcolor = 219; //pink
break;
case 8:
numcolor = 93; //violet
break;
case 9:
numcolor = 12; //blue
break;
case 10:
numcolor = 14; //cyan
break;
case 11:
numcolor = 118; //green
break;
case 12:
numcolor = 226; //yellow
break;
case 13:
numcolor = 214; //orange
break;
}*/
switch (direct) {
case 1: // up
while (getline (model61, temp61)) {
for (int j = 0; j < col; j++) {
if (temp61[j] == '2') // main body of portal
*ct++ = numcolor * 100 + serial;
else if (temp61[j] == '1') // ground
*ct++ = GRD_C * 100 + 1;
else // air
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 2: // down
while (getline (model62, temp62)) {
for (int j = 0; j < col; j++) {
if (temp62[j] == '2')
*ct++ = numcolor * 100 + serial;
else if (temp62[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 3: // left
while (getline (model63, temp63)) {
for (int j = 0; j < col; j++) {
if (temp63[j] == '2')
*ct++ = numcolor * 100 + serial;
else if (temp63[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 4: // right
while (getline (model64, temp64)) {
for (int j = 0; j < col; j++) {
if (temp64[j] == '2')
*ct++ = numcolor * 100 + serial;
else if (temp64[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
}
}
else if (overall / 10 >= 2) { // player and elfin and property ground and gravity converter
int serial = overall / 10;
int fi = overall % 10;
int color = 0;
switch(fi) {
case 1: // ice
color = 32;
break;
case 2: // fire
color = 1;
break;
}
switch(serial) {
case 2: // property ground
while (getline (model1, temp10)) {
for (int j = 0; j < col; j++) {
if (temp10[j] == '1')
*ct++ = color * 100 + overall;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 3: // elfin
while (getline(model3, temp3)) {
for (int i = 0; i < ELFIN_W; i++) {
if (temp3[i] == '1')
*ct++ = color * 100 + overall;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 5: // lower gravity converter
if (fi == 1) {
while (getline (model51, temp51)) {
for (int j = 0; j < col; j++) {
if (temp51[j] == '2')
*ct++ = 21 * 100 + 5;
else if (temp51[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
}
else { // upper gravity converter
while (getline (model52, temp52)) {
for (int j = 0; j < col; j++) {
if (temp52[j] == '2')
*ct++ = 21 * 100 + 5;
else if (temp52[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
}
ct = cont;
break;
}
}
else { // not portal
switch(overall) {
case 0: //air
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
*ct++ = AIR_C * 100 + 0;
break;
case 1: // ground
while (getline (model1, temp1)) {
for (int j = 0; j < col; j++) {
if (temp1[j] == '1')
*ct++ = GRD_C * 100 + overall;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
case 4: // gate
while (getline (model4, temp4)) {
for (int j = 0; j < col; j++) {
if (temp4[j] == '2')
*ct++ = 131 * 100 + overall;
else if (temp4[j] == '1')
*ct++ = GRD_C * 100 + 1;
else
*ct++ = AIR_C * 100 + 0;
}
}
ct = cont;
break;
}
}
model1.close();
model3.close();
model4.close();
model51.close();
model52.close();
model61.close();
model62.close();
model63.close();
model64.close();
}
/*
fill the content of the player
input: int variable property, pointer pointing to an int array
no return value
*/
void player_fill(int property, int *cont) {
int color;
switch(property) {
case 1: // ice
color = 32;
break;
case 2: // fire
color = 1;
break;
}
int *ct = cont;
for (int i = 0; i < 2 * 2; i++)
*ct++ = color * 100 + 2;
}