Skip to content

Commit

Permalink
started refactoring CAGame
Browse files Browse the repository at this point in the history
  • Loading branch information
kpawlak committed Jul 12, 2024
1 parent 488083f commit 425aa61
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 76 deletions.
175 changes: 107 additions & 68 deletions src/ComputationalArt/CAGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
]
16 changes: 8 additions & 8 deletions src/ComputationalArt/CAGrid.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [
Expand All @@ -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 [
Expand All @@ -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 [
Expand Down

0 comments on commit 425aa61

Please sign in to comment.