Skip to content

Commit

Permalink
Adding some helper class side methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Mar 17, 2021
1 parent 973e254 commit 81cd888
Showing 1 changed file with 73 additions and 15 deletions.
88 changes: 73 additions & 15 deletions src/Bloc-Memory/MGGameElement.class.st
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
"
| board space |
board := MGGameElement example.
I'm a game visual board.
## To open a game
```
| aGameElement space |
aGameElement := MGGameElement new memoryGame: MGGame withNumbers; yourself.
space := BlSpace new.
space addChild: aGameElement.
space pulse.
space extent: aGameElement extent.
space show.
```
## To open a game in a separate native window
```
| aGameElement space |
aGameElement := MGGameElement new memoryGame: MGGame withNumbers; yourself.
space := BlSpace new.
space extent: 420@420.
space addChild: board.
space host: BlOSWindowSDL2Host new.
space addChild: aGameElement.
space pulse.
space extent: aGameElement extent.
space show.
{ board . space } inspect
```
"
Class {
#name : #MGGameElement,
Expand All @@ -16,20 +35,59 @@ Class {
#category : #'Bloc-Memory-Elements'
}

{ #category : #example }
MGGameElement class >> example [
<sampleInstance>

^ self new memoryGame: MGGame withNumbers; yourself

]

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

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

space := BlSpace new.
space extent: 420@420.
space addChild: gameElement.
space show.
self openOnModel: MGGame withNumbers inSpace: (BlSpace new extent: 420@420; yourself)

]

{ #category : #example }
MGGameElement class >> exampleInASpaceInAnOSWindow [
<sampleInstance>

self nativelyOpenOnModel: MGGame withNumbers inSpace: BlSpace new.
]

{ #category : #opening }
MGGameElement class >> nativelyOpenOnModel: aModel inSpace: aSpace [

aSpace host: BlOSWindowSDL2Host new.
^ self openOnModel: aModel inSpace: aSpace.
]

{ #category : #'instance creation' }
MGGameElement class >> onModel: aModel [

^ self new memoryGame: aModel; yourself
]

{ #category : #'instance creation' }
MGGameElement class >> onModel: aModel inSpace: aSpace [

| game |
game := self onModel: aModel.
aSpace addChild: game.
^ game
]

{ #category : #opening }
MGGameElement class >> openOnModel: aModel inSpace: aSpace [

| game |
game := self onModel: aModel inSpace: aSpace.
aSpace pulse.
aSpace show.
^ game
]

{ #category : #initialization }
Expand Down

0 comments on commit 81cd888

Please sign in to comment.