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
|
-
|
|
|
|
-
|
|
-
|
|
-
|
|
-
|
|
|
|
-
|
!
-
|
!
!
|
!
-
|
-
|
!
-
|
|
!
| #module SRPGSerch
#deffunc srpginit str s1, int p1, int p2
map = s1 mapsizeX = p1 mapsizeY = p2 vx = 0, 1, 0, -1 vy = -1, 0, 1, 0 return
#deffunc serch@SRPGSerch int power
poke result, y*mapsizeX+x, power+'0' if power > 0 {
repeat 4 step++ serchX = x + vx(cnt) serchY = y + vy(cnt) if (serchX<0)|(serchY<0)|(serchX>=mapsizeX)|(serchY>=mapsizeY) {
logmes strf("[step%03d]地点("+serchX+","+serchY+")は移動不可能です", step)
} else {
i = power-(peek(map, serchY*mapsizeX+serchX)-'0')
if i>=0 { j = peek(result, serchY*mapsizeX+serchX)-'0' if j<i { x = serchX : y = serchY logmes strf("[step%03d]地点("+serchX+","+serchY+")は移動可能です", step)
serch i x -= vx(cnt) : y -= vy(cnt) } else { logmes strf("[step%03d]地点("+serchX+","+serchY+")は既に調査完了しています", step)
}
} else { logmes strf("[step%03d]地点("+serchX+","+serchY+")は移動不可能です", step)
}
}
loop
}
return
#deffunc mapserch var v1, int p2, int p3, int p4
sdim result, mapsizeX*mapsizeY+1
memset result, ' ', mapsizeX*mapsizeY x = p2 : y = p3 step = 0 serch p4 sdim v1, mapsizeX*mapsizeY+1
memcpy v1, result, mapsizeX*mapsizeY return
#deffunc draw_sq int p1, int p2, int p3
line p1*p3+2, p2*p3+2, (p1+1)*p3-3, p2*p3+2
line (p1+1)*p3-3, p2*p3+2, (p1+1)*p3-3, (p2+1)*p3-3
line (p1+1)*p3-3, (p2+1)*p3-3, p1*p3+2, (p2+1)*p3-3
line p1*p3+2, (p2+1)*p3-3, p1*p3+2, p2*p3+2
return
#global
#define MAPX 11 #define MAPY 11 #define MOVE 4 #define SQSIZE 32 screen 0, MAPX*SQSIZE, MAPY*SQSIZE
title "クリックでユニット位置変更"
randomize
sdim map, MAPX*MAPY+1
repeat MAPX*MAPY if rnd(4)==0 {
poke map, cnt, '2'
} else {
poke map, cnt, '1'
}
loop
srpginit map, MAPX, MAPY onclick goto *click
*click
mx = limit(mousex/SQSIZE, 0, MAPX-1)
my = limit(mousey/SQSIZE, 0, MAPY-1)
mapserch s, mx, my, MOVE
redraw 0
repeat MAPY : c1 = cnt
repeat MAPX
a = 255-64*(peek(map, c1*MAPX+cnt)-'0') color a, a, a : boxf cnt*SQSIZE, c1*SQSIZE, (cnt+1)*SQSIZE, (c1+1)*SQSIZE
i = strf("%c", peek(s, c1*MAPX+cnt)) if (i != " ") { color 255, 255, 255 : draw_sq cnt, c1, SQSIZE
pos cnt*SQSIZE+12, c1*SQSIZE+8 : mes i }
loop
loop
color 255, 255, 255 circle mx*SQSIZE, my*SQSIZE, (mx+1)*SQSIZE, (my+1)*SQSIZE
redraw 1
stop
|