-
Notifications
You must be signed in to change notification settings - Fork 0
/
推箱子_.c
80 lines (71 loc) · 1.37 KB
/
推箱子_.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
#include <stdio.h>
#include <stdlib.h>
#include <getch.h>
int main()
{
char map[8][8] = {
{0,0,3,3,3,3,0,0},
{0,0,3,5,5,3,0,0},
{0,3,3,0,5,3,3,0},
{0,3,0,0,4,5,3,0},
{3,3,0,4,0,0,3,3},
{3,0,0,3,4,4,0,3},
{3,0,0,2,0,0,0,3},
{3,3,3,3,3,3,3,3},
};
int x = 6 , y = 3 , step = 0;
for(;;)
{
system("clear");
int cnt = 0;
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++)
{
switch(map[i][j])
{
case 0: printf(" "); break;
case 2: printf("@ "); break;
case 3: printf("# "); break;
case 4: printf("$ "); break;
case 5: printf("O "); break;
case 7: printf("@ "); break;
case 9: printf("$ "); cnt++;
}
}
printf("\n");
}
if(4 == cnt)
{
printf("恭喜完成任务,一共走%d步!\n", step);
return 0;
}
int ox = 0 , oy = 0;
switch(getch())
{
case 183: ox--; break;
case 184: ox++; break;
case 185: oy++; break;
case 186: oy--; break;
}
if(0 == map[x+ox][y+oy] || 5 == map[x+ox][y+oy])
{
map[x+ox][y+oy] += 2;
map[x][y] -= 2;
x += ox;
y += oy;
step++;
continue;
}
if((4 == map[x+ox][y+oy] || 9==map[x+ox][y+oy]) &&
(0 == map[x+ox*2][y+oy*2] || 5 == map[x+ox*2][y+oy*2]))
{
map[x+ox*2][y+oy*2] += 4;
map[x+ox][y+oy] -= 2;
map[x][y] -= 2;
x += ox;
y += oy;
step++;
}
}
}