From 425aa611bfd6bb9e3eb0f249c24d4ba53092c569 Mon Sep 17 00:00:00 2001 From: kpawlak Date: Fri, 12 Jul 2024 19:28:34 +0200 Subject: [PATCH] started refactoring CAGame --- src/ComputationalArt/CAGame.class.st | 175 ++++++++++++++++----------- src/ComputationalArt/CAGrid.class.st | 16 +-- 2 files changed, 115 insertions(+), 76 deletions(-) diff --git a/src/ComputationalArt/CAGame.class.st b/src/ComputationalArt/CAGame.class.st index d753460..fa068df 100644 --- a/src/ComputationalArt/CAGame.class.st +++ b/src/ComputationalArt/CAGame.class.st @@ -20,130 +20,168 @@ Class { } { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'JAL 6/23/2024 17:34' + #category : #constants, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:19' +} +CAGame class >> brushSize [ + + ^ 1. +] + +{ + #category : #constants, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:20' +} +CAGame class >> frameDelay [ + + ^ 0.01. +] + +{ + #category : #'initialize-release', + #'squeak_changestamp' : 'KoPa 7/12/2024 19:23' +} +CAGame class >> initializeRuleSet [ + + ^ OrderedCollection new + add: CARuleFallDown new; + add: CARuleSink new; + add: CARuleFluidFlowLeft new; + add: CARuleFluidFlowRight new; + add: CARulePyramidLeft new; + add: CARulePyramidRight new; + add: CARuleAlgaeDie new; + add: CARuleAlgaeGrow new; + add: CARuleRise new; + add: CARuleGasFlowLeft new; + add: CARuleGasFlowRight new; + add: CARuleGasDisappear new; + add: CARuleFireOut new; + add: CARuleBurn new; + add: CARuleFishSwimLeft new; + add: CARuleFishSwimRight new; + add: CARuleFishSwimUp new; + add: CARuleFishSwimDown new; + add: CARuleFishDie new; + add: CARuleTntSpread new; + add: CARuleStonerLife new; + yourself. +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:07' } CAGame >> activeCellType [ - ^activeCellType + + ^ activeCellType. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 7/3/2024 16:02' + #category : #accessing, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:07' } CAGame >> brushActive [ - ^ brushActive + + ^ brushActive. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/16/2024 20:52' + #category : #accessing, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:08' } CAGame >> brushSize: aSize [ - brushSize := aSize + + brushSize := aSize. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/23/2024 16:51' + #category : #functional, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:08' } CAGame >> clear [ + CAGrid clear: grid. screen step. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/16/2024 20:51' + #category : #accessing, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:08' } CAGame >> frameDelay: aSecondCount [ - frameDelay := aSecondCount + frameDelay := aSecondCount. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/19/2024 16:20' + #category : #'initialize-release', + #'squeak_changestamp' : 'KoPa 7/12/2024 19:27' } -CAGame >> putCellAtRow: row andCol: col [ +CAGame >> initialize [ +] + +{ + #category : #functional, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:13' +} +CAGame >> putCellAtRow: aRow andCol: aCol [ + | originRow originCol placeRow placeCol | - originRow := row - brushSize. - originCol := col - brushSize. - 1 - to: brushSize * 2 - 1 - do: [:rowIndex | 1 + originRow := aRow - brushSize. + originCol := aCol - brushSize. + 1 to: brushSize * 2 - 1 + do: [ :rowIndex | 1 to: brushSize * 2 - 1 - do: [:colIndex | + do: [ :colIndex | placeRow := originRow + rowIndex. placeCol := originCol + colIndex. (placeRow > 0 and: placeRow < 101 and: placeCol > 0 and: placeCol < 101) - ifTrue: [grid + ifTrue: [ grid putCell: activeCellType atRow: placeRow - andCol: placeCol]]]. - screen step + andCol: placeCol. ]]]. + screen step. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/16/2024 14:19' + #category : #accessing, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:13' } -CAGame >> setActiveCellTypeTo: cellType [ +CAGame >> setActiveCellTypeTo: aType [ - activeCellType := cellType + activeCellType := aType. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 7/10/2024 14:42' + #category : #functional, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:14' } -CAGame >> skipAhead: stepCount [ +CAGame >> skipAhead: aStepCount [ - stepCount timesRepeat: [ruler applyRules: ruleSet to: grid.]. - screen step + aStepCount timesRepeat: [ ruler applyRules: ruleSet to: grid. ]. + screen step. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'KoPa 7/12/2024 18:38' + #category : #'initialize-release', + #'squeak_changestamp' : 'KoPa 7/12/2024 19:27' } CAGame >> start [ + | maxIterations iterationCount gameloop ui | isRunning := true. - frameDelay := 0.01. - brushSize := 1. + frameDelay := CAGame frameDelay. + brushSize := CAGame brushSize. brushActive := false. ruler := CARuler new. activeCellType := CABlocks tnt. - ruleSet := OrderedCollection new add: CARuleFallDown new; - add: CARuleSink new; - add: CARuleFluidFlowLeft new; - add: CARuleFluidFlowRight new; - add: CARulePyramidLeft new; - add: CARulePyramidRight new; - add: CARuleAlgaeDie new; - add: CARuleAlgaeGrow new; - add: CARuleRise new; - add: CARuleGasFlowLeft new; - add: CARuleGasFlowRight new; - add: CARuleGasDisappear new; - add: CARuleFireOut new; - add: CARuleBurn new; - add: CARuleFishSwimLeft new; - add: CARuleFishSwimRight new; - add: CARuleFishSwimUp new; - add: CARuleFishSwimDown new; - add: CARuleFishDie new; - add: CARuleTntSpread new; - add: CARuleStonerLife new; - - yourself. + ruleSet := CAGame initializeRuleSet. grid := CAGrid new. - CAGrid fill: grid. screen := CADisplay new. screen attachedGame: self. screen attachedGrid: grid. @@ -167,18 +205,19 @@ CAGame >> start [ ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 7/3/2024 15:52' + #category : #toggle, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:10' } CAGame >> toggleBrushActive [ + brushActive := brushActive not. - Transcript show:'tog'; cr. ] { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'Sars 6/12/2024 15:01' + #category : #toggle, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:11' } CAGame >> toggleRunning [ + isRunning := isRunning not. ] diff --git a/src/ComputationalArt/CAGrid.class.st b/src/ComputationalArt/CAGrid.class.st index e7f1091..a87b118 100644 --- a/src/ComputationalArt/CAGrid.class.st +++ b/src/ComputationalArt/CAGrid.class.st @@ -10,16 +10,16 @@ Class { } { - #category : #'as yet unclassified', - #'squeak_changestamp' : 'HaMa 6/20/2024 10:48' + #category : #functional, + #'squeak_changestamp' : 'KoPa 7/12/2024 19:18' } -CAGrid class >> clear: aGrid [ +CAGrid class >> clear: aGrid [ + | numCols numRows col | numCols := aGrid numCols. numRows := aGrid numRows. col := #(0 0). - 1 - to: numRows + 1 to: numRows do: [:rowIndex | 1 to: numCols do: [:colIndex | aGrid @@ -29,7 +29,7 @@ CAGrid class >> clear: aGrid [ ] { - #category : #'as yet unclassified', + #category : #functional, #'squeak_changestamp' : 'Sars 6/16/2024 20:45' } CAGrid class >> fill: aGrid [ @@ -53,7 +53,7 @@ CAGrid class >> fill: aGrid [ ] { - #category : #'as yet unclassified', + #category : #functional, #'squeak_changestamp' : 'HaMa 6/20/2024 11:14' } CAGrid class >> fillStone: aGrid [ @@ -71,7 +71,7 @@ CAGrid class >> fillStone: aGrid [ ] { - #category : #'as yet unclassified', + #category : #functional, #'squeak_changestamp' : 'HaMa 6/20/2024 11:14' } CAGrid class >> fillTNT: aGrid [