cell.st 559 Bytes
Newer Older
1
2
3
4
5
6
7
8
Object subclass: Cell [
    | state |
    <comment: 'I am an object in a cell that is either alive or dead'>

    Cell class >> newAlive: alive [
        | c |
        c := super new.
        c initAlive: alive.
9
        ^c ]
10

11
    initAlive: alive [ state := alive. ]
12
13
14
15
16
17
18

    aliveValue := Cell newAlive: true.
    deadValue := Cell newAlive: false.

    printOn: stream [
        state
            ifTrue: [ ' x |' displayOn: stream ]
19
            ifFalse: [ '   |' displayOn: stream ] ] ]
20
21
22

Cell class extend [
    alive [ ^aliveValue ]
23
    dead [ ^deadValue ] ]