Skip to content

Commit

Permalink
Merge pull request #63 from hpi-swa-teaching/fix/ls/clear
Browse files Browse the repository at this point in the history
added clear method to game
  • Loading branch information
lasumn authored Jun 23, 2024
2 parents 7ebf126 + 951af5b commit 4acad5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
28 changes: 17 additions & 11 deletions src/ComputationalArt/CAGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ CAGame >> brushSize: aSize [
brushSize := aSize
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 16:51'
}
CAGame >> clear [
CAGrid clear: grid.
screen step.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:51'
Expand Down Expand Up @@ -83,10 +92,10 @@ CAGame >> skipAhead: stepCount [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 15:56'
#'squeak_changestamp' : 'Sars 6/23/2024 16:40'
}
CAGame >> start [
| maxIterations iterationCount gameloop ui|
| maxIterations iterationCount gameloop ui |
isRunning := true.
frameDelay := 0.2.
brushSize := 1.
Expand All @@ -111,31 +120,28 @@ CAGame >> start [
add: CARuleFishSwimUpEX new;
add: CARuleFishSwimDownEX new;
add: CARuleFishDieEX new;
add: CARuleTntSpreadEX new withOccurrences: 1;
add: CARuleTntSpreadEX new;
yourself.
grid := CAGrid new.
CAGrid fill: grid.
screen := CADisplay new.
screen attachedGame: self.
screen attachedGrid: grid.
cellViewMorph := screen viewMorph.


ui := CAOverlay new.
ui position: 130@130.
ui position: 130 @ 130.
ui game: self.
cellViewMorph addMorph: ui.
cellViewMorph position: 750@250.

cellViewMorph position: 750 @ 250.
screen step.
maxIterations := 300.
maxIterations := 200.
iterationCount := 0.
gameloop := [[iterationCount < maxIterations]
whileTrue: [(Delay forSeconds: frameDelay) wait.
isRunning
ifTrue: [grid := ruler applyRules: ruleSet to: grid.
screen step. iterationCount := iterationCount + 1].
].
screen step.
iterationCount := iterationCount + 1]].
Transcript show: 'Game loop terminated after ' , maxIterations printString , ' iterations.';
cr] fork
]
Expand Down
30 changes: 18 additions & 12 deletions src/ComputationalArt/CAOverlay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ CAOverlay >> game: aCAGame [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 15:27'
#'squeak_changestamp' : 'Sars 6/23/2024 16:48'
}
CAOverlay >> initialize [
| lastHeight menus|
| lastHeight menus |
super initialize.

menus := OrderedCollection new.
menus add: CAOverlayPlayMenu new.
menus add: CAOverlayBlockMenu new.
menus add: CAOverlayBrushMenu new.

lastHeight := 0.
menus do: [:m |
m y: lastHeight.
m fitChildren; padding: (Rectangle origin: 10@10 corner: 10@30).
lastHeight := lastHeight + m height.
self addMorph: m].
lastHeight := 0.
menus
do: [:m |
m y: lastHeight.
m fitChildren;
padding: (Rectangle origin: 10 @ 10 corner: 10 @ 30).
lastHeight := lastHeight + m height.
self addMorph: m].
self fitChildren.
self padding: (Rectangle origin: 10@10 corner: 10@10).
self color: Color gray.
self
padding: (Rectangle origin: 10 @ 10 corner: 10 @ 10).
self
color: (Color
r: 0.5
g: 0.5
b: 0.5
alpha: 0.3)
]
4 changes: 2 additions & 2 deletions src/ComputationalArt/CAOverlayPlayMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 15:03'
#'squeak_changestamp' : 'Sars 6/23/2024 16:34'
}
CAOverlayPlayMenu >> initialize [
| pauseList |
Expand All @@ -21,7 +21,7 @@ CAOverlayPlayMenu >> initialize [
item contents = '=' ifTrue: [item contents: '>'. self owner game toggleRunning.]].
item contents = '+1' ifTrue: [self owner game skipAhead: 1.].
item contents = '+10' ifTrue: [self owner game skipAhead: 10.].
item contents = 'clear' ifTrue: [CAGrid clear: (self owner game).].
item contents = 'clear' ifTrue: [self owner game clear.].
].
self addMorph: pauseList.
pauseList y: 70.
Expand Down

0 comments on commit 4acad5a

Please sign in to comment.