-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.mode.learn.coffee
More file actions
137 lines (137 loc) · 6.18 KB
/
Copy pathclient.mode.learn.coffee
File metadata and controls
137 lines (137 loc) · 6.18 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
sceneMaker["learn"] = ->
addGameButtons = ->
ui.board.addButton("返回", new Point(0, -80), -> ui.board.hideDialog())
ui.board.addButton("退出", new Point(0, 80), GoHome)
addGameButtons()
remoteGet("/tutorial.wei7", (tutorial) ->
elements = {}
codifyElement(elements, """
<table id="info1Table" style="width: 100%; height: 100%; text-align: center;"
xmlns="http://www.w3.org/1999/xhtml">
<tr><td style="padding: 0 6.25%; color: rgb(104,104,104);">
<div id="regularMenuItems" style="font-size: 1.3em;" />
<div style="font-size: 2em;">
<div id="parentButton" style="width: 20%; display: inline-block;
cursor: pointer;">↰</div>
<div id="backwardButton" style="width: 20%; display: inline-block;
cursor: pointer;">←</div>
<div id="forwardButton" style="width: 20%; display: inline-block;
cursor: pointer;">→</div>
</div>
<div id="currentMoveNumberLabel" style="font-size: 1.3em; margin-top: 0.5em;" />
</td></tr>
</table>
""")
codifyElement(elements, """
<table id="info2Table" style="width: 100%; height: 100%;"
xmlns="http://www.w3.org/1999/xhtml">
<tr><td style="padding: 0 6.25%;">
<div id="evaluationLabel" style="text-align: center; font-size: 4em;
color: rgb(0,128,0);" />
<div id="commentLabel" style="font-size: 1em; color: rgb(104,104,104);" />
</td></tr>
</table>
""")
ui.info1.appendChild(elements.info1Table)
ui.info2.appendChild(elements.info2Table)
setElementClickHandler(elements.parentButton, (event) ->
gotoParent()
refresh()
, undefined, true)
setElementClickHandler(elements.backwardButton, (event) ->
moveBackward()
refresh()
, undefined, true)
setElementClickHandler(elements.forwardButton, (event) ->
moveForward()
refresh()
, undefined, true)
refresh = ->
walker = context.scene.walker
branch = walker.getCurrentBranch()
emptyElement(elements.regularMenuItems)
if walker.isLastStop() and branch.branches?
for m, i in branch.branches
menuItem = parseElement("""
<div style="cursor: pointer; width: 100%; background-color: rgb(192,192,192);
margin: 0.5em 0; padding: 0.5em 0;"
xmlns="http://www.w3.org/1999/xhtml">#{m.title}</div>
""")
menuItem.branchIndex = i
do (menuItem) ->
setElementClickHandler(menuItem, (event) ->
gotoBranch(menuItem.branchIndex)
refresh()
, undefined, true)
elements.regularMenuItems.appendChild(menuItem)
emptyElement(ui.boardMarks)
ui.board.addMark(m.symbol, new Point(m.point.x, m.point.y)) for m in \
if walker.position.stepIndex == -1
branch.pre?.marks ? []
else
branch.steps[walker.position.stepIndex].marks ? []
elements.currentMoveNumberLabel.textContent =
GameHelper.getMoveNumberText(context.game.moves.length - 1)
elements.evaluationLabel.textContent =
if walker.position.stepIndex == -1
""
else
GameHelper.getEvaluationText(branch.steps[walker.position.stepIndex]
.action.value.evaluation)
elements.commentLabel.textContent =
if walker.position.stepIndex == -1
branch.pre?.comment ? ""
else
branch.steps[walker.position.stepIndex].comment ? ""
gotoBranch = (index) ->
walker = context.scene.walker
if index? then walker.gotoChild(index)
branch = walker.getCurrentBranch()
if walker.position.stepIndex == -1
if branch.pre?.stones?
GameHelper.addStonesInBoard(branch.pre.stones.map((m) ->
{color: m.color, position: new Point(m.point.x, m.point.y)}
))
else
playMove()
gotoParent = ->
walker = context.scene.walker
branch = walker.getCurrentBranch()
stepIndex = walker.position.stepIndex
walker.gotoParent()
if branch.steps? and stepIndex >= 0
GameHelper.takebackMovesInBoard(branch.steps[..stepIndex]
.filter(walker.stopCondition).length)
if branch.pre?.stones?
GameHelper.removeStonesInBoard()
moveBackward = ->
walker = context.scene.walker
branch = walker.getCurrentBranch()
try
walker.gotoPreviousStop()
GameHelper.takebackMovesInBoard(1)
catch e
preStones = branch.pre?.stones
walker.gotoParent()
if preStones?
GameHelper.removeStonesInBoard()
moveForward = ->
walker = context.scene.walker
walker.gotoNextStop()
playMove()
playMove = ->
walker = context.scene.walker
branch = walker.getCurrentBranch()
step = branch.steps[walker.position.stepIndex]
move = step.action.value
GameHelper.playMoveInBoard(
color: move.color
position: new Point(move.point.x, move.point.y)
)
context.scene.walker = new GameRecordWalker(tutorial)
context.scene.walker.stopCondition = (m) -> m.action.type == "move"
# ui.board.isBlocked = false
context.game = new Game(19, Game.COLOR_BLACK)
gotoBranch()
refresh()
)