-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamebase.c
More file actions
314 lines (301 loc) · 5.31 KB
/
gamebase.c
File metadata and controls
314 lines (301 loc) · 5.31 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "gamebase.h"
int point;
int g1_point;
//편의함수
void nums_to_arr(int** p, int a, int b, int c, int d, int e, int f, int g, int h)
{
p[0][0] = a;
p[0][1] = b;
p[1][0] = c;
p[1][1] = d;
p[2][0] = e;
p[2][1] = f;
p[3][0] = g;
p[3][1] = h;
return;
}
int spin(int n)
{
if (n == 3) return 0;
else return n + 1;
}
int anti_spin(int n)
{
if (n == 0) return 3;
else return n - 1;
}
void show_graphic(char*** p)
{
int i, j = 0;
for (i = 0; i < 30; i++)
{
for (j = 0; j < 30; j++)
{
printf("%s", p[i][j]);
}
printf("\n");
}
printf(" 현재점수 : %d", point);
return;
}
int arrow(char key)
{
switch (key)
{
case 72:
return 0;
case 75:
return 1;
case 77:
return 3;
case 80:
return 2;
default:
return -1;
}
}
int anti_arrow(char key)
{
switch (key)
{
case 72:
return 2;
case 75:
return 3;
case 77:
return 1;
case 80:
return 0;
default:
return -1;
}
}
void show_coords(int** block_coors, int* location)
{
int i;
for (i = 0; i < 4; i++)
{
printf("%3d%3d\n", location[0] + block_coors[i][0], location[1] + block_coors[i][1]);
}
return;
}
void coor_to_coor(int** p, int** q)
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
p[i][j] = q[i][j];
}
}
return;
}
/********블록관련**********/
//블럭정보를 받으면 중심기준 점들의 위치를 반환
void block_type_to_coors(int** p, int blocktype, int spinvalue)
{
switch (blocktype)
{
case 0:
switch (spinvalue)
{
case 0:
nums_to_arr(p, -1, 0, 0, 0, 1, 0, 2, 0);
return;
case 1:
nums_to_arr(p, 0, -1, 0, 0, 0, 1, 0, 2);
return;
case 2:
nums_to_arr(p, -1, 0, 0, 0, 1, 0, 2, 0);
return;
case 3:
nums_to_arr(p, 0, -1, 0, 0, 0, 1, 0, 2);
return;
}
case 1:
switch (spinvalue)
{
case 0:
nums_to_arr(p, -1, -1, 0, -1, 0, 0, 0, 1);
return;
case 1:
nums_to_arr(p, -1, 0, 0, 0, 1, 0, 1, -1);
return;
case 2:
nums_to_arr(p, 0, -1, 0, 0, 0, 1, 1, 1);
return;
case 3:
nums_to_arr(p, -1, 0, -1, 1, 0, 0, 1, 0);
return;
}
case 2:
switch (spinvalue)
{
case 0:
nums_to_arr(p, 0, -1, 0, 0, 0, 1, -1, 1);
return;
case 1:
nums_to_arr(p, -1, -1, -1, 0, 0, 0, 1, 0);
return;
case 2:
nums_to_arr(p, 1, -1, 0, -1, 0, 0, 0, 1);
return;
case 3:
nums_to_arr(p, -1, 0, 0, 0, 1, 0, 1, 1);
return;
}
case 3:
switch (spinvalue)
{
case 0:
nums_to_arr(p, -1, 0, 0, 0, 0, 1, 1, 1);
return;
case 1:
nums_to_arr(p, 0, -1, 0, 0, -1, 0, -1, 1);
return;
case 2:
nums_to_arr(p, -1, 0, 0, 0, 0, 1, 1, 1);
return;
case 3:
nums_to_arr(p, 0, -1, 0, 0, -1, 0, -1, 1);
return;
}
case 4:
switch (spinvalue)
{
case 0:
nums_to_arr(p, 0, 0, 0, 1, -1, 1, 1, 0);
return;
case 1:
nums_to_arr(p, -1, -1, -1, 0, 0, 0, 0, 1);
return;
case 2:
nums_to_arr(p, 0, 0, 0, 1, -1, 1, 1, 0);
return;
case 3:
nums_to_arr(p, -1, -1, -1, 0, 0, 0, 0, 1);
return;
}
case 5:
switch (spinvalue)
{
case 0:
nums_to_arr(p, 0, 0, 0, 1, 1, 0, 1, 1);
return;
case 1:
nums_to_arr(p, 0, 0, 0, 1, 1, 0, 1, 1);
return;
case 2:
nums_to_arr(p, 0, 0, 0, 1, 1, 0, 1, 1);
return;
case 3:
nums_to_arr(p, 0, 0, 0, 1, 1, 0, 1, 1);
return;
}
}
}
//좌표, 블록점좌표배열, 기준점을 받으면 블럭을 그래픽에 찍음
void put_block(char*** p, int** q, int a, int b)
{
int i, tempi, tempj;
for (i = 0; i < 4; i++)
{
tempi = a + q[i][0];
tempj = b + q[i][1];
p[tempi][tempj] = "■";
}
}
//좌표, 블록점좌표배열, 기준점을 받으면 블럭을 그래픽에서 지움
void del_block(char*** p, int** q, int a, int b)
{
int i, tempi, tempj;
for (i = 0; i < 4; i++)
{
tempi = a + q[i][0];
tempj = b + q[i][1];
p[tempi][tempj] = " ";
}
}
//기준점, 방향키를 입력받으면 기준점을 변환
void move_coors(int* location, int key)
{
int i;
switch (key)
{
case 0:
location[0] -= 1;
return;
case 1:
location[1] -= 1;
return;
case 2:
location[0] += 1;
return;
case 3:
location[1] += 1;
return;
}
}
//블럭상대좌표, 기준점을 입력받으면 그래픽에 찍을 수 있는지를 판단
int can_put(char*** graphic, int** block_coors, int* location)
{
int a, b, i;
for (i = 0; i < 4; i++)
{
a = location[0] + block_coors[i][0];
b = location[1] + block_coors[i][1];//a,b가 각각의 사각형좌표에 대응
if ((b < 10) || (b > 19)) return 0;
if (graphic[a][b] != " ") return 0;
}
return 1;
}
/*******게임진행******/
//그래픽, 행을 입력받으면 해당 행이 꽉찼는지를 판단
int is_row_full(char*** graphic, int r)
{
int j;
for (j = 10; j < 20; j++) if (graphic[r][j] == " ") return 0;
return 1;
}
//그래픽을 받으면 줄지워주며 그래픽도 보여줌
void row_clear(char*** graphic)
{
int i, j, k, high = 4;
for (i = 24; i > high; i--)
{
if (is_row_full(graphic, i))//i열이 꽉찼으면
{
graphic[i][10] = "▣";
graphic[i][11] = "▣";
graphic[i][12] = "▣";
system("cls");
show_graphic(graphic);
graphic[i][13] = "▣";
graphic[i][14] = "▣";
graphic[i][15] = "▣";
system("cls");
show_graphic(graphic);
graphic[i][16] = "▣";
graphic[i][17] = "▣";
system("cls");
show_graphic(graphic);
graphic[i][18] = "▣";
graphic[i][19] = "▣";
system("cls");
show_graphic(graphic);
for (k = i; k > high; k--)//i행부터 위로 쭉
{
for (j = 10; j < 20; j++)//모든 열에
{
graphic[k][j] = graphic[k - 1][j];
}
}
i++;
high++;
point += 1000;
g1_point += 1000;
}
}
}
//□■▩▣