Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BlElement subclass: #MonstaGraphicsElement
- instanceVariableNames: 'monsta'
- classVariableNames: ''
- package: 'RPG-bloc-semestral'
- "Now methods of the MonstaGraphicsElement will follow"
- backgroundPaint
- "Return a BlPaint that should be used as a background (fill)
- of both back and face sides of the card. Color is polymorphic
- with BlPaint and therefore can be used too"
- <return: #BlPaint or: #Color>
- ^ Color lightGray
- drawOn: aCanvas
- | font textPainter metrics baseline origin textToDraw|
- font := aCanvas font
- size: self textFontSize;
- build.
- (monsta isNil)
- ifTrue: [ textToDraw := 'Monsta is null' ]
- ifFalse: [ textToDraw := self monsta displayName asString ].
- textPainter := aCanvas text
- font: font;
- paint: Color white;
- string: textToDraw asString.
- metrics := textPainter measure.
- origin := (self extent - metrics textMetrics bounds extent) / 2.0.
- "baseline := origin - metrics textMetrics bounds origin."
- textPainter
- baseline: origin;
- draw
- drawOnSpartaCanvas: aCanvas
- | roundedRectangle |
- aCanvas fill
- paint: self backgroundPaint;
- path: self boundsInLocal;
- draw.
- self drawOn: aCanvas.
- "
- roundedRectangle := aCanvas shape
- roundedRectangle: self boundsInLocal
- radii: (BlCornerRadii radius: self cornerRadius).
- aCanvas clip
- by: roundedRectangle
- during: [
- self drawCommonOn: aCanvas.
- self drawOn: aCanvas
- self card isFlipped
- ifTrue: [ self drawFlippedSideOn: aCanvas ]
- ifFalse: [ self drawBacksideOn: aCanvas ] ]"
- initialize
- super initialize.
- self size: 80@80
- monsta
- ^monsta
- monsta: aMonsta
- monsta := aMonsta
- textFontSize
- ^40
- "END OF methods of the MonstaGraphicsElement"
- BlElement subclass: #GameBoard
- instanceVariableNames: 'theGameModel mapFields'
- classVariableNames: ''
- package: 'RPG-bloc-semestral'
- "Now methods of the GameBoard will follow"
- backgroundPaint
- <return: #BlPaint or: #Color>
- ^ Color black
- drawOn: aCanvas
- aCanvas fill
- paint: self backgroundPaint;
- path: self boundsInLocal;
- draw.
- drawOnSpartaCanvas: aCanvas
- aCanvas fill
- paint: self backgroundPaint;
- path: self boundsInLocal;
- draw.
- self drawOn: aCanvas.
- gameModel
- ^theGameModel
- gameModel: aModel
- theGameModel := aModel.
- aModel allMonsters
- do: [ :aMonsta | self addChild: (self newFieldElement monsta: aMonsta) ]
- initialize
- super initialize.
- self background: (BlBackground paint: Color gray darker).
- self layout: (BlGridLayout horizontal cellSpacing: 20).
- self constraintsDo: [ :layoutConstraints |
- layoutConstraints horizontal fitContent.
- layoutConstraints vertical fitContent ]
- newFieldElement
- ^ MonstaGraphicsElement new
- "END OF methods of the GameBoard"
- Object subclass: #GameModel
- instanceVariableNames: ''
- classVariableNames: 'allMonsters selectedMonsta'
- package: 'RPG-bloc-semestral'
- "methods of the GameModel"
- allMonsters
- ^allMonsters
- chooseMonster: aMonster
- "check if such a monta is selected"
- (selectedMonsta = aMonster)
- ifTrue: [ ^ self ].
- selectedMonsta := aMonster
- initialize
- super initialize.
- allMonsters := OrderedCollection new
- "---------------------------------------------------------------"
- Now when I Inspect following code, in View, no graphics is visible, despite fact that the DrawOnSpartaCanvas is overriden in GameBoard.
- | board game |
- game := GameModel new.
- board := GameBoard new.
- board gameModel: game.
- board
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement