-
Notifications
You must be signed in to change notification settings - Fork 1
/
gop_autogen.go
453 lines (449 loc) · 10.7 KB
/
gop_autogen.go
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// Code generated by gop (Go+); DO NOT EDIT.
package main
import "github.com/goplus/spx"
const _ = true
type Button4 struct {
spx.SpriteImpl
*Game
}
type Cat1 struct {
spx.SpriteImpl
*Game
}
type Chess struct {
spx.SpriteImpl
*Game
id int
}
type CurrentChess struct {
spx.SpriteImpl
*Game
}
type Undoer struct {
spx.SpriteImpl
*Game
}
type Game struct {
spx.Game
Chess Chess
Button4 Button4
CurrentChess CurrentChess
Cat1 Cat1
Undoer Undoer
undoIdList spx.List
undoOpList spx.List
undoParamList spx.List
gameState spx.List
restoreList spx.List
visitList spx.List
col int
currentCol int
_White int
_Eating int
_Black int
pos int
ret int
mayBeEaten int
currentPlayer int
currentRow int
undoing int
player int
row int
eatNum int
eatenPlayer int
restoreNum int
}
//line main.spx:31:1
func (this *Game) initConsts() {
//line main.spx:32:1
this._Black = 1
//line main.spx:33:1
this._White = 2
//line main.spx:34:1
this._Eating = 3
}
//line main.spx:37:1
func (this *Game) calcHitPosition(x float64, y float64) {
//line main.spx:38:1
this.col = spx.Iround((x + 159) / 17.7)
//line main.spx:39:1
this.row = spx.Iround((y - 159) / -17.7)
//line main.spx:40:1
if this.row < 0 || this.col < 0 || this.row > 18 || this.col > 18 {
//line main.spx:41:1
this.ret = 0
} else {
//line main.spx:43:1
this.ret = this.row*19 + this.col + 1
}
}
//line main.spx:47:1
func (this *Game) initGameState() {
//line main.spx:48:1
this.gameState.Delete(spx.All)
//line main.spx:49:1
for
//line main.spx:49:1
i := 0; i < 361;
//line main.spx:49:1
i++ {
spx.Sched()
//line main.spx:50:1
this.gameState.Append(0)
}
}
//line main.spx:54:1
func (this *Game) checkEat() {
//line main.spx:55:1
this.eatNum = 0
//line main.spx:56:1
this.eatenPlayer = 3 - this.currentPlayer
//line main.spx:57:1
this.checkEatChess(this.currentRow+1, this.currentCol, this.eatenPlayer)
//line main.spx:58:1
this.checkEatChess(this.currentRow-1, this.currentCol, this.eatenPlayer)
//line main.spx:59:1
this.checkEatChess(this.currentRow, this.currentCol+1, this.eatenPlayer)
//line main.spx:60:1
this.checkEatChess(this.currentRow, this.currentCol-1, this.eatenPlayer)
//line main.spx:61:1
this.restoreRestoreList(this.eatenPlayer)
//line main.spx:62:1
if this.eatNum == 0 {
//line main.spx:63:1
this.eatenPlayer = this.currentPlayer
//line main.spx:64:1
this.checkEatChess(this.currentRow, this.currentCol, this.eatenPlayer)
//line main.spx:65:1
this.restoreRestoreList(this.eatenPlayer)
}
//line main.spx:67:1
if this.eatNum > 0 {
//line main.spx:68:1
this.Broadcast__1("eat chesses", true)
}
}
//line main.spx:72:1
func (this *Game) checkEatChess(row int, col int, expectPlayer int) {
//line main.spx:73:1
this.mayBeEaten = 1
//line main.spx:74:1
this.confirmChessEatenOrNot(row, col, expectPlayer)
//line main.spx:75:1
if this.mayBeEaten == 1 {
//line main.spx:76:1
this.eatNum += this.visitList.Len()
} else {
//line main.spx:78:1
this.pos = 1
//line main.spx:79:1
for
//line main.spx:79:1
i := this.visitList.Len(); i > 0;
//line main.spx:79:1
i-- {
spx.Sched()
//line main.spx:80:1
this.restoreList.Append(this.visitList.At(this.pos - 1))
//line main.spx:81:1
this.pos++
}
}
//line main.spx:84:1
this.visitList.Delete(spx.All)
}
//line main.spx:87:1
func (this *Game) confirmChessEatenOrNot(row int, col int, expectPlayer int) {
//line main.spx:88:1
if this.mayBeEaten == 1 && !(row < 0 || col < 0 || row > 18 || col > 18) {
//line main.spx:89:1
this.pos = row*19 + (col + 1)
//line main.spx:90:1
this.player = this.gameState.At(this.pos - 1).Int()
//line main.spx:91:1
if this.player == expectPlayer {
//line main.spx:92:1
this.visitList.Append(this.pos)
//line main.spx:93:1
this.gameState.Set(this.pos-1, this._Eating)
//line main.spx:94:1
this.confirmChessEatenOrNot(row+1, col, expectPlayer)
//line main.spx:95:1
this.confirmChessEatenOrNot(row-1, col, expectPlayer)
//line main.spx:96:1
this.confirmChessEatenOrNot(row, col+1, expectPlayer)
//line main.spx:97:1
this.confirmChessEatenOrNot(row, col-1, expectPlayer)
} else
//line main.spx:99:1
if this.player == 0 {
//line main.spx:100:1
this.mayBeEaten = 0
}
}
}
//line main.spx:106:1
func (this *Game) restoreRestoreList(expectPlayer int) {
//line main.spx:107:1
this.restoreNum = this.restoreList.Len()
//line main.spx:108:1
this.pos = 1
//line main.spx:109:1
for
//line main.spx:109:1
i := this.restoreList.Len(); i > 0;
//line main.spx:109:1
i-- {
spx.Sched()
//line main.spx:110:1
this.gameState.Set(this.restoreList.At(this.pos-1).Int()-1, expectPlayer)
//line main.spx:111:1
this.pos++
}
//line main.spx:113:1
this.restoreList.Delete(spx.All)
}
//line main.spx:116
func (this *Game) MainEntry() {
//line main.spx:116:1
this.OnStart(func() {
//line main.spx:117:1
this.initConsts()
//line main.spx:118:1
this.initGameState()
//line main.spx:119:1
this.currentPlayer = this._Black
})
//line main.spx:122:1
this.OnClick(func() {
//line main.spx:123:1
this.calcHitPosition(this.MouseX(), this.MouseY())
//line main.spx:124:1
if this.ret > 0 && this.gameState.At(this.ret-1).Int() == 0 {
//line main.spx:125:1
this.currentCol = this.col
//line main.spx:126:1
this.currentRow = this.row
//line main.spx:127:1
this.Broadcast__0("try put chess")
}
})
//line main.spx:131:1
this.OnMsg__1("confirm to put chess", func() {
//line main.spx:132:1
spx.Gopt_SpriteImpl_Clone__0(&this.Chess)
})
//line main.spx:135:1
this.OnMsg__1("put chess done", func() {
//line main.spx:136:1
this.checkEat()
//line main.spx:137:1
this.currentPlayer = 3 - this.currentPlayer
})
}
func (this *Game) Main() {
spx.Gopt_Game_Main(this, new(Button4), new(Cat1), new(Chess), new(CurrentChess), new(Undoer))
}
//line Button4.spx:1
func (this *Button4) Main() {
//line Button4.spx:1:1
this.OnStart(func() {
//line Button4.spx:2:1
this.Hide()
})
//line Button4.spx:5:1
this.OnClick(func() {
//line Button4.spx:6:1
this.Broadcast__0("confirm to put chess")
//line Button4.spx:7:1
this.Hide()
})
//line Button4.spx:10:1
this.OnMsg__1("try put chess", func() {
//line Button4.spx:11:1
this.Show()
})
}
func (this *Button4) Classfname() string {
return "Button4"
}
//line Cat1.spx:1
func (this *Cat1) Main() {
//line Cat1.spx:1:1
this.OnStart(func() {
//line Cat1.spx:2:1
this.Hide()
})
//line Cat1.spx:5:1
this.OnMsg__1("game over", func() {
//line Cat1.spx:6:1
this.Show()
//line Cat1.spx:7:1
if this.currentPlayer == this._Black {
//line Cat1.spx:8:1
this.Say__1("The black side won!", 3)
} else {
//line Cat1.spx:10:1
this.Say__1("The white side won!", 3)
}
//line Cat1.spx:12:1
spx.Exit__1()
})
}
func (this *Cat1) Classfname() string {
return "Cat1"
}
//line Chess.spx:3:1
func (this *Chess) putChess(op int, id int, val int, newval int) {
//line Chess.spx:4:1
this.gameState.Set(id-1, newval)
//line Chess.spx:5:1
if this.undoing == 0 {
//line Chess.spx:6:1
this.undoOpList.Append(op)
//line Chess.spx:7:1
this.undoIdList.Append(id)
//line Chess.spx:8:1
this.undoParamList.Append(val)
}
}
//line Chess.spx:12
func (this *Chess) Main() {
//line Chess.spx:12:1
this.OnCloned__1(func() {
//line Chess.spx:13:1
this.id = this.currentRow*19 + this.currentCol + 1
//line Chess.spx:14:1
this.putChess(0, this.id, this.currentPlayer, this.currentPlayer)
//line Chess.spx:15:1
this.SetXYpos(float64(this.currentCol)*17.7-159, float64(this.currentRow)*-17.7+159)
//line Chess.spx:16:1
this.SetCostume__2(this.currentPlayer - 1)
//line Chess.spx:17:1
this.Show()
//line Chess.spx:18:1
if this.undoing == 0 {
//line Chess.spx:19:1
this.Broadcast__0("put chess done")
} else {
//line Chess.spx:21:1
this.Broadcast__0("restore eaten chesses")
}
})
//line Chess.spx:25:1
this.OnMsg__1("eat chesses", func() {
//line Chess.spx:26:1
if this.gameState.At(this.id-1).Int() == this._Eating {
//line Chess.spx:27:1
this.putChess(this._Eating, this.id, this.eatenPlayer, 0)
//line Chess.spx:28:1
this.Destroy()
}
})
}
func (this *Chess) Classfname() string {
return "Chess"
}
//line CurrentChess.spx:1
func (this *CurrentChess) Main() {
//line CurrentChess.spx:1:1
this.OnStart(func() {
//line CurrentChess.spx:2:1
this.Hide()
})
//line CurrentChess.spx:5:1
this.OnMsg__1("put chess done", func() {
//line CurrentChess.spx:6:1
this.Hide()
})
//line CurrentChess.spx:9:1
this.OnMsg__1("try put chess", func() {
//line CurrentChess.spx:10:1
this.SetXYpos(float64(this.currentCol)*17.7-159, float64(this.currentRow)*-17.7+159)
//line CurrentChess.spx:11:1
this.SetCostume__2(this.currentPlayer - 1)
//line CurrentChess.spx:12:1
this.Show()
})
}
func (this *CurrentChess) Classfname() string {
return "CurrentChess"
}
//line Undoer.spx:1:1
func (this *Undoer) undo(op int, id int, val int) {
//line Undoer.spx:2:1
this.undoOpList.Delete(spx.Last)
//line Undoer.spx:3:1
this.undoIdList.Delete(spx.Last)
//line Undoer.spx:4:1
this.undoParamList.Delete(spx.Last)
//line Undoer.spx:5:1
this.currentCol = (id - 1) % 19
//line Undoer.spx:6:1
this.currentRow = (id - 1) / 19
//line Undoer.spx:7:1
this.currentPlayer = val
//line Undoer.spx:8:1
if op == 0 {
//line Undoer.spx:9:1
if this.undoOpList.Len() == 0 {
//line Undoer.spx:10:1
this.Hide()
}
//line Undoer.spx:12:1
this.Broadcast__1("try put chess", true)
//line Undoer.spx:13:1
this.gameState.Set(id-1, this._Eating)
//line Undoer.spx:14:1
this.Broadcast__1("eat chesses", true)
//line Undoer.spx:15:1
this.undoing = 0
} else {
//line Undoer.spx:17:1
spx.Gopt_SpriteImpl_Clone__0(&this.Chess)
}
}
//line Undoer.spx:21
func (this *Undoer) Main() {
//line Undoer.spx:21:1
this.OnStart(func() {
//line Undoer.spx:22:1
this.undoOpList.Delete(spx.All)
//line Undoer.spx:23:1
this.undoIdList.Delete(spx.All)
//line Undoer.spx:24:1
this.undoParamList.Delete(spx.All)
//line Undoer.spx:25:1
this.undoing = 0
//line Undoer.spx:26:1
this.Hide()
})
//line Undoer.spx:29:1
this.OnClick(func() {
//line Undoer.spx:30:1
if this.undoOpList.Len() > 0 {
//line Undoer.spx:31:1
this.undoing = 1
//line Undoer.spx:32:1
this.undo(this.undoOpList.At(spx.Last).Int(), this.undoIdList.At(spx.Last).Int(), this.undoParamList.At(spx.Last).Int())
}
})
//line Undoer.spx:36:1
this.OnMsg__1("restore eaten chesses", func() {
//line Undoer.spx:37:1
this.currentPlayer = 3 - this.currentPlayer
//line Undoer.spx:38:1
this.undo(this.undoOpList.At(spx.Last).Int(), this.undoIdList.At(spx.Last).Int(), this.undoParamList.At(spx.Last).Int())
})
//line Undoer.spx:41:1
this.OnMsg__1("put chess done", func() {
//line Undoer.spx:42:1
this.Show()
})
}
func (this *Undoer) Classfname() string {
return "Undoer"
}
func main() {
new(Game).Main()
}