Advertisement
Guest User

Pharo semestral

a guest
Nov 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. BlElement subclass: #MonstaGraphicsElement
  2. instanceVariableNames: 'monsta'
  3. classVariableNames: ''
  4. package: 'RPG-bloc-semestral'
  5.  
  6. "Now methods of the MonstaGraphicsElement will follow"
  7. backgroundPaint
  8. "Return a BlPaint that should be used as a background (fill)
  9. of both back and face sides of the card. Color is polymorphic
  10. with BlPaint and therefore can be used too"
  11. <return: #BlPaint or: #Color>
  12.  
  13. ^ Color lightGray
  14.  
  15. drawOn: aCanvas
  16. | font textPainter metrics baseline origin textToDraw|
  17.  
  18. font := aCanvas font
  19. size: self textFontSize;
  20. build.
  21.  
  22. (monsta isNil)
  23. ifTrue: [ textToDraw := 'Monsta is null' ]
  24. ifFalse: [ textToDraw := self monsta displayName asString ].
  25.  
  26. textPainter := aCanvas text
  27. font: font;
  28. paint: Color white;
  29. string: textToDraw asString.
  30.  
  31. metrics := textPainter measure.
  32.  
  33. origin := (self extent - metrics textMetrics bounds extent) / 2.0.
  34. "baseline := origin - metrics textMetrics bounds origin."
  35.  
  36. textPainter
  37. baseline: origin;
  38. draw
  39.  
  40.  
  41. drawOnSpartaCanvas: aCanvas
  42. | roundedRectangle |
  43. aCanvas fill
  44. paint: self backgroundPaint;
  45. path: self boundsInLocal;
  46. draw.
  47.  
  48. self drawOn: aCanvas.
  49. "
  50. roundedRectangle := aCanvas shape
  51. roundedRectangle: self boundsInLocal
  52. radii: (BlCornerRadii radius: self cornerRadius).
  53.  
  54. aCanvas clip
  55. by: roundedRectangle
  56. during: [
  57. self drawCommonOn: aCanvas.
  58. self drawOn: aCanvas
  59. self card isFlipped
  60. ifTrue: [ self drawFlippedSideOn: aCanvas ]
  61. ifFalse: [ self drawBacksideOn: aCanvas ] ]"
  62.  
  63.  
  64. initialize
  65. super initialize.
  66.  
  67. self size: 80@80
  68.  
  69.  
  70. monsta
  71. ^monsta
  72.  
  73. monsta: aMonsta
  74. monsta := aMonsta
  75.  
  76. textFontSize
  77. ^40
  78.  
  79.  
  80. "END OF methods of the MonstaGraphicsElement"
  81.  
  82. BlElement subclass: #GameBoard
  83. instanceVariableNames: 'theGameModel mapFields'
  84. classVariableNames: ''
  85. package: 'RPG-bloc-semestral'
  86.  
  87.  
  88. "Now methods of the GameBoard will follow"
  89.  
  90. backgroundPaint
  91. <return: #BlPaint or: #Color>
  92.  
  93. ^ Color black
  94.  
  95. drawOn: aCanvas
  96. aCanvas fill
  97. paint: self backgroundPaint;
  98. path: self boundsInLocal;
  99. draw.
  100.  
  101. drawOnSpartaCanvas: aCanvas
  102. aCanvas fill
  103. paint: self backgroundPaint;
  104. path: self boundsInLocal;
  105. draw.
  106.  
  107. self drawOn: aCanvas.
  108.  
  109.  
  110. gameModel
  111. ^theGameModel
  112.  
  113. gameModel: aModel
  114. theGameModel := aModel.
  115.  
  116. aModel allMonsters
  117. do: [ :aMonsta | self addChild: (self newFieldElement monsta: aMonsta) ]
  118.  
  119. initialize
  120. super initialize.
  121.  
  122. self background: (BlBackground paint: Color gray darker).
  123.  
  124. self layout: (BlGridLayout horizontal cellSpacing: 20).
  125. self constraintsDo: [ :layoutConstraints |
  126. layoutConstraints horizontal fitContent.
  127. layoutConstraints vertical fitContent ]
  128.  
  129. newFieldElement
  130. ^ MonstaGraphicsElement new
  131.  
  132. "END OF methods of the GameBoard"
  133.  
  134. Object subclass: #GameModel
  135. instanceVariableNames: ''
  136. classVariableNames: 'allMonsters selectedMonsta'
  137. package: 'RPG-bloc-semestral'
  138.  
  139. "methods of the GameModel"
  140.  
  141. allMonsters
  142. ^allMonsters
  143.  
  144. chooseMonster: aMonster
  145. "check if such a monta is selected"
  146.  
  147. (selectedMonsta = aMonster)
  148. ifTrue: [ ^ self ].
  149. selectedMonsta := aMonster
  150.  
  151. initialize
  152. super initialize.
  153. allMonsters := OrderedCollection new
  154.  
  155. "---------------------------------------------------------------"
  156. Now when I Inspect following code, in View, no graphics is visible, despite fact that the DrawOnSpartaCanvas is overriden in GameBoard.
  157.  
  158.  
  159. | board game |
  160. game := GameModel new.
  161. board := GameBoard new.
  162. board gameModel: game.
  163. board
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement