Skip to content

Commit 4acad5a

Browse files
Merge pull request #63 from hpi-swa-teaching/fix/ls/clear
added clear method to game
2 parents 7ebf126 + 951af5b commit 4acad5a

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

src/ComputationalArt/CAGame.class.st

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ CAGame >> brushSize: aSize [
2626
brushSize := aSize
2727
]
2828

29+
{
30+
#category : #'as yet unclassified',
31+
#'squeak_changestamp' : 'Sars 6/23/2024 16:51'
32+
}
33+
CAGame >> clear [
34+
CAGrid clear: grid.
35+
screen step.
36+
]
37+
2938
{
3039
#category : #'as yet unclassified',
3140
#'squeak_changestamp' : 'Sars 6/16/2024 20:51'
@@ -83,10 +92,10 @@ CAGame >> skipAhead: stepCount [
8392

8493
{
8594
#category : #'as yet unclassified',
86-
#'squeak_changestamp' : 'Sars 6/23/2024 15:56'
95+
#'squeak_changestamp' : 'Sars 6/23/2024 16:40'
8796
}
8897
CAGame >> start [
89-
| maxIterations iterationCount gameloop ui|
98+
| maxIterations iterationCount gameloop ui |
9099
isRunning := true.
91100
frameDelay := 0.2.
92101
brushSize := 1.
@@ -111,31 +120,28 @@ CAGame >> start [
111120
add: CARuleFishSwimUpEX new;
112121
add: CARuleFishSwimDownEX new;
113122
add: CARuleFishDieEX new;
114-
add: CARuleTntSpreadEX new withOccurrences: 1;
123+
add: CARuleTntSpreadEX new;
115124
yourself.
116125
grid := CAGrid new.
117126
CAGrid fill: grid.
118127
screen := CADisplay new.
119128
screen attachedGame: self.
120129
screen attachedGrid: grid.
121130
cellViewMorph := screen viewMorph.
122-
123-
124131
ui := CAOverlay new.
125-
ui position: 130@130.
132+
ui position: 130 @ 130.
126133
ui game: self.
127134
cellViewMorph addMorph: ui.
128-
cellViewMorph position: 750@250.
129-
135+
cellViewMorph position: 750 @ 250.
130136
screen step.
131-
maxIterations := 300.
137+
maxIterations := 200.
132138
iterationCount := 0.
133139
gameloop := [[iterationCount < maxIterations]
134140
whileTrue: [(Delay forSeconds: frameDelay) wait.
135141
isRunning
136142
ifTrue: [grid := ruler applyRules: ruleSet to: grid.
137-
screen step. iterationCount := iterationCount + 1].
138-
].
143+
screen step.
144+
iterationCount := iterationCount + 1]].
139145
Transcript show: 'Game loop terminated after ' , maxIterations printString , ' iterations.';
140146
cr] fork
141147
]

src/ComputationalArt/CAOverlay.class.st

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,30 @@ CAOverlay >> game: aCAGame [
2525

2626
{
2727
#category : #'as yet unclassified',
28-
#'squeak_changestamp' : 'JAL 6/23/2024 15:27'
28+
#'squeak_changestamp' : 'Sars 6/23/2024 16:48'
2929
}
3030
CAOverlay >> initialize [
31-
| lastHeight menus|
31+
| lastHeight menus |
3232
super initialize.
33-
3433
menus := OrderedCollection new.
3534
menus add: CAOverlayPlayMenu new.
3635
menus add: CAOverlayBlockMenu new.
3736
menus add: CAOverlayBrushMenu new.
38-
39-
lastHeight := 0.
40-
menus do: [:m |
41-
m y: lastHeight.
42-
m fitChildren; padding: (Rectangle origin: 10@10 corner: 10@30).
43-
lastHeight := lastHeight + m height.
44-
self addMorph: m].
37+
lastHeight := 0.
38+
menus
39+
do: [:m |
40+
m y: lastHeight.
41+
m fitChildren;
42+
padding: (Rectangle origin: 10 @ 10 corner: 10 @ 30).
43+
lastHeight := lastHeight + m height.
44+
self addMorph: m].
4545
self fitChildren.
46-
self padding: (Rectangle origin: 10@10 corner: 10@10).
47-
self color: Color gray.
46+
self
47+
padding: (Rectangle origin: 10 @ 10 corner: 10 @ 10).
48+
self
49+
color: (Color
50+
r: 0.5
51+
g: 0.5
52+
b: 0.5
53+
alpha: 0.3)
4854
]

src/ComputationalArt/CAOverlayPlayMenu.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Class {
66

77
{
88
#category : #'as yet unclassified',
9-
#'squeak_changestamp' : 'JAL 6/23/2024 15:03'
9+
#'squeak_changestamp' : 'Sars 6/23/2024 16:34'
1010
}
1111
CAOverlayPlayMenu >> initialize [
1212
| pauseList |
@@ -21,7 +21,7 @@ CAOverlayPlayMenu >> initialize [
2121
item contents = '=' ifTrue: [item contents: '>'. self owner game toggleRunning.]].
2222
item contents = '+1' ifTrue: [self owner game skipAhead: 1.].
2323
item contents = '+10' ifTrue: [self owner game skipAhead: 10.].
24-
item contents = 'clear' ifTrue: [CAGrid clear: (self owner game).].
24+
item contents = 'clear' ifTrue: [self owner game clear.].
2525
].
2626
self addMorph: pauseList.
2727
pauseList y: 70.

0 commit comments

Comments
 (0)