Skip to content

Commit

Permalink
Followed some missing steps in Bloc-Memory.
Browse files Browse the repository at this point in the history
The booklet filename is "2017-11-09-memorygame.pdf",
referenced from README.md.
  • Loading branch information
tinchodias committed Feb 25, 2021
1 parent a9486ca commit 31e635e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
16 changes: 15 additions & 1 deletion src/Bloc-Memory/MGCardElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,21 @@ MGCardElement >> drawCommonOn: aCanvas [

{ #category : #drawing }
MGCardElement >> drawFlippedSideOn: aCanvas [
"nothing for now"

| font origin textPainter metrics |
font := aCanvas font
named: 'Source Sans Pro';
size: 50;
build.
textPainter := aCanvas text
font: font;
paint: Color white;
string: self card symbol asString.
metrics := textPainter measure.
origin := self extent - metrics textMetrics bounds extent / 2.0.
textPainter
baseline: origin;
draw
]

{ #category : #drawing }
Expand Down
19 changes: 19 additions & 0 deletions src/Bloc-Memory/MGCardEventListener.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Class {
#name : #MGCardEventListener,
#superclass : #BlEventListener,
#instVars : [
'memoryGame'
],
#category : #'Bloc-Memory-Elements'
}

{ #category : #'mouse handlers' }
MGCardEventListener >> clickEvent: anEvent [

memoryGame chooseCard: anEvent currentTarget card
]

{ #category : #accessing }
MGCardEventListener >> memoryGame: aGame [
memoryGame := aGame
]
50 changes: 37 additions & 13 deletions src/Bloc-Memory/MGGameElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,66 @@ Class {
#name : #MGGameElement,
#superclass : #BlElement,
#instVars : [
'memoryGame'
'game'
],
#category : #'Bloc-Memory-Elements'
}

{ #category : #example }
MGGameElement class >> example [
"self example"
MGGameElement class >> exampleInASpace [
<example>

| game board |
| space game gameElement |
game := MGGame withNumbers.
board := MGGameElement new.
board memoryGame: game.
^ board
gameElement := self new.
gameElement memoryGame: game.

space := BlSpace new.
space extent: 420@420.
space addChild: gameElement.
space show.

]

{ #category : #initialization }
MGGameElement >> initialize [

super initialize.
self layout: BlGridLayout horizontal.

self background: (BlBackground paint: Color gray darker).
self layout: (BlGridLayout horizontal cellSpacing: 20).

self constraintsDo: [ :aLayoutConstraints |
aLayoutConstraints horizontal fitContent.
aLayoutConstraints vertical fitContent ]
]

{ #category : #accessing }
MGGameElement >> memoryGame [
^ memoryGame
^ game
]

{ #category : #accessing }
MGGameElement >> memoryGame: anObject [
memoryGame := anObject.
memoryGame availableCards
do: [ :aCard | self addChild: (self newCardElement card: aCard) ]
MGGameElement >> memoryGame: aGame [

| aCardEventListener |
game := aGame.
aCardEventListener := self newCardEventListener memoryGame: aGame.
self layout columnCount: game gridSize.
game availableCards do: [ :aCard |
| cardElement |
cardElement := self newCardElement card: aCard.
cardElement addEventHandler: aCardEventListener.
self addChild: cardElement ]
]

{ #category : #accessing }
MGGameElement >> newCardElement [
^ MGCardElement new
]

{ #category : #'instance creation' }
MGGameElement >> newCardEventListener [

^ MGCardEventListener new
]

0 comments on commit 31e635e

Please sign in to comment.