Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/GToolkit-Demo-Ludo/GtLudoDieElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Class {
#name : #GtLudoDieElement,
#superclass : #BlElement,
#instVars : [
'die'
'die',
'doubleClickHandler'
],
#category : #'GToolkit-Demo-Ludo-UI'
}
Expand Down Expand Up @@ -46,6 +47,11 @@ GtLudoDieElement >> dieWidth [
^ 3 * self dotWidth + (4 * self dotSpace)
]

{ #category : #'api - enablement' }
GtLudoDieElement >> disable [
self removeEventHandler: doubleClickHandler
]

{ #category : #constants }
GtLudoDieElement >> dotSpace [
"Space between a dot and the edge of the die or another dot"
Expand All @@ -57,6 +63,11 @@ GtLudoDieElement >> dotWidth [
^ 20
]

{ #category : #'api - enablement' }
GtLudoDieElement >> enable [
self addEventHandler: doubleClickHandler
]

{ #category : #constants }
GtLudoDieElement >> facePositions [
"These are the positions on the 3x3 grid of the dots for each face value from 1 to 6.
Expand Down Expand Up @@ -101,11 +112,12 @@ GtLudoDieElement >> initializeAnnouncements [
when: GtLudoDieRolled
send: #onRolled
to: self.
self
when: BlDoubleClickEvent
do: [ :anEvent |
anEvent consumed: true.
self die roll ].
doubleClickHandler := BlEventHandler
on: BlDoubleClickEvent
do: [ :anEvent |
anEvent consumed: true.
self die roll ].
self addEventHandler: doubleClickHandler.
self onRolled
]

Expand Down
15 changes: 10 additions & 5 deletions src/GToolkit-Demo-Ludo/GtLudoGameElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,26 @@ GtLudoGameElement >> initialize [
GtLudoGameElement >> initializeFor: aGame [
game := aGame.
self
constraintsDo:
[ :c |
constraintsDo: [ :c |
c vertical fitContent.
c horizontal fitContent ].
self
addChild:
((aGame boardElement)
addChild: (aGame boardElement
addDieElement;
yourself).
self addChild: self feedbackElement.
self onFeedbackUpdate.
game announcer
when: GtLudoBoardFeedbackUpdated
send: #onFeedbackUpdate
to: self
to: self.
game die announcer
when: GtLudoDieRolled
do: [ game playerToRoll ifFalse: [ (self query // GtLudoDieElement) anyOne disable ] ].
game announcer
when: GtLudoGameUpdated
do: [ (game isOver not and: [ game playerToRoll ])
ifTrue: [ (self query // GtLudoDieElement) anyOne enable ] ]
]

{ #category : #feedback }
Expand Down