SimpleSwitchMorph subclass: #SBECell instanceVariableNames: 'mouseAction' classVariableNames: '' poolDictionaries: '' category: 'SBE-Quinto'! !SBECell methodsFor: 'initialization' stamp: 'sa 5/28/2009 15:18'! initialize super initialize. self label: ''. self borderWidth: 2. bounds := 0@0 corner: 16@16. offColor := Color paleYellow. onColor := Color paleBlue darker. self useSquareCorners. self turnOff! ! !SBECell methodsFor: 'event handling' stamp: 'sa 5/28/2009 15:37'! mouseAction: aBlock ^ mouseAction := aBlock! ! !SBECell methodsFor: 'event handling' stamp: 'sa 5/28/2009 15:38'! mouseUp: anEvent mouseAction value! ! BorderedMorph subclass: #SBEGame instanceVariableNames: 'cells mouseAction' classVariableNames: '' poolDictionaries: '' category: 'SBE-Quinto'! !SBEGame methodsFor: 'initialization' stamp: 'sa 5/28/2009 15:24'! initialize | sampleCell width height n | super initialize. n := self cellsPerSide. sampleCell := SBECell new. width := sampleCell width. height := sampleCell height. self bounds: (5@5 extent: ((width*n) @(height*n)) + (2 * self borderWidth)). cells := Matrix new: n tabulate: [ :i :j | self newCellAt: i at: j ].! ! !SBEGame methodsFor: 'gamelogic' stamp: 'sa 5/28/2009 15:26'! cellsPerSide "The number of cells along each side of the game" ^ 10! ! !SBEGame methodsFor: 'gamelogic' stamp: 'sa 5/28/2009 15:35'! newCellAt: i at: j "Create a cell for position (i,j) and add it to my on--screen representation at the appropriate screen position. Answer the new cell" | c origin | c := SBECell new. origin := self innerBounds origin. self addMorph: c. c position: ((i -- 1) * c width) @ ((j -- 1) * c height) + origin. c mouseAction: [self toggleNeighboursOfCellAt: i at: j]. ^ c! ! !SBEGame methodsFor: 'gamelogic' stamp: 'i at: i - 1 6/4/2009 12:57'! toggleNeighboursOfCellAt: i at: j (i > 1) ifTrue: [ (cells at: i - 1 at: j ) toggleState]. (i < self cellsPerSide) ifTrue: [ (cells at: i + 1 at: j) toggleState]. (j > 1) ifTrue: [ (cells at: i at: j - 1) toggleState]. (j < self cellsPerSide) ifTrue: [ (cells at: i at: j + 1) toggleState].! !