A new version of EToys was added to project The Inbox:
http://source.squeak.org/inbox/EToys-kfr.377.mcz ==================== Summary ==================== Name: EToys-kfr.377 Author: kfr Time: 17 January 2020, 11:11:14.960611 pm UUID: ca9f5e38-21b2-7648-b98d-09fc2644d0c3 Ancestors: EToys-dtl.376 3 different levels and hi score for Mines =============== Diff against EToys-dtl.376 =============== Item was changed: AlignmentMorph subclass: #Mines + instanceVariableNames: 'board minesDisplay timeDisplay helpText level levels levelButton hiScoreDisplay' - instanceVariableNames: 'board minesDisplay timeDisplay helpText' classVariableNames: '' poolDictionaries: '' category: 'Etoys-Squeakland-Morphic-Games'! Item was added: + ----- Method: Mines class>>initialize (in category 'parts bin') ----- + initialize + super initialize. + "boardSizes are column, row, mines, highScore" + BoardSizes := Dictionary new. + BoardSizes at: 'Expert' put:{30. 16. 99. 999}. + BoardSizes at: 'Intermediate' put:{16. 16. 40. 999}. + BoardSizes at: 'Beginner' put:{8. 8. 10. 999}. + + ! Item was added: + ----- Method: Mines>>hiScoreDisplay (in category 'access') ----- + hiScoreDisplay + + ^ hiScoreDisplay! Item was changed: ----- Method: Mines>>initialize (in category 'initialization') ----- initialize "initialize the state of the receiver" + super initialize. + levels := {'Beginner'. 'Intermediate'. 'Expert'}. + level := levels first. - "" self listDirection: #topToBottom; wrapCentering: #center; cellPositioning: #topCenter; vResizing: #shrinkWrap; hResizing: #shrinkWrap; layoutInset: 3; addMorph: self makeControls; addMorph: self board. helpText := nil. + self newGame! Item was added: + ----- Method: Mines>>level (in category 'access') ----- + level + ^level! Item was changed: ----- Method: Mines>>makeControls (in category 'initialize') ----- makeControls | row | row := AlignmentMorph newRow color: color; borderWidth: 2; layoutInset: 3. row borderStyle: BorderStyle inset. row hResizing: #spaceFill; vResizing: #shrinkWrap; wrapCentering: #center; cellPositioning: #leftCenter; extent: 5 @ 5. row addMorph: (self buildButton: SimpleSwitchMorph new target: self label: ' Help ' translated selector: #help:). row addMorph: (self + buildButton: (levelButton := SimpleButtonMorph new) + target: self + label: level asString translated + selector: #nextLevel). + row + addMorph: (self buildButton: SimpleButtonMorph new target: self label: ' Quit ' translated selector: #delete). "row addMorph: (self buildButton: SimpleButtonMorph new target: self label: ' Hint ' translated selector: #hint)." row addMorph: (self buildButton: SimpleButtonMorph new target: self label: ' New game ' translated selector: #newGame). minesDisplay := LedMorph new digits: 2; extent: 2 * 10 @ 15. row addMorph: (self wrapPanel: minesDisplay label: 'Mines:' translated). + timeDisplay := LedTimerMorph new digits: 3; extent: 3 * 10 @ 15. + - timeDisplay := LedTimerMorph new digits: 3; - extent: 3 * 10 @ 15. row addMorph: (self wrapPanel: timeDisplay label: 'Time:' translated). + hiScoreDisplay := LedMorph new digits: 3; extent: 3 * 10 @ 15. + row + addMorph: (self wrapPanel: hiScoreDisplay label: 'Hi Score:' translated). ^ row! Item was changed: ----- Method: Mines>>newGame (in category 'actions') ----- newGame + | boardSize | + boardSize := BoardSizes at: level. - timeDisplay value: 0; flash: false. timeDisplay stop. timeDisplay reset. + minesDisplay value: (boardSize at: 3). + hiScoreDisplay value: (boardSize at: 4). + self board resetBoard: level.! - minesDisplay value: 99. - self board resetBoard.! Item was added: + ----- Method: Mines>>nextLevel (in category 'access') ----- + nextLevel + | nextLevel | + nextLevel := (levels indexOf:level) + 1. + nextLevel = 4 ifTrue:[nextLevel := 1]. + level := levels at:(nextLevel). + levelButton label: level asString. + self newGame + + ! Item was changed: AlignmentMorph subclass: #MinesBoard + instanceVariableNames: 'protoTile rows columns flashCount tileCount target actionSelector arguments gameStart gameOver boardSize' - instanceVariableNames: 'protoTile rows columns flashCount tileCount target actionSelector arguments gameStart gameOver' classVariableNames: '' poolDictionaries: '' category: 'Etoys-Squeakland-Morphic-Games'! Item was changed: ----- Method: MinesBoard>>initialize (in category 'initialization') ----- initialize "initialize the state of the receiver" super initialize. "" target := nil. actionSelector := #selection. arguments := #(). "" self layoutPolicy: nil; hResizing: #rigid; vResizing: #rigid. "" + boardSize := BoardSizes at:'Beginner'. + - rows := self preferredRows. columns := self preferredColumns. + rows := self preferredRows. flashCount := 0. "" self extent: self protoTile extent * (columns @ rows). self adjustTiles. + self resetBoard: 'Beginner'.! - self resetBoard! Item was changed: ----- Method: MinesBoard>>preferredColumns (in category 'preferences') ----- preferredColumns + ^ boardSize at: 1! - ^ 30! Item was changed: ----- Method: MinesBoard>>preferredMines (in category 'preferences') ----- preferredMines + ^boardSize at:3! - ^ 99! Item was changed: ----- Method: MinesBoard>>preferredRows (in category 'preferences') ----- preferredRows + ^ boardSize at:2! - ^ 16! Item was removed: - ----- Method: MinesBoard>>resetBoard (in category 'initialization') ----- - resetBoard - - gameStart := false. - gameOver := false. - [flashCount = 0] whileFalse: [self step]. - flashCount := 0. - tileCount := 0. - Collection initialize. "randomize the Collection class" - self purgeAllCommands. - self submorphsDo: "set tiles to original state." - [:m | m privateOwner: nil. "Don't propagate all these changes..." - m mineFlag: false. - m disabled: false. - m switchState: false. - m isMine: false. - m privateOwner: self]. - self changed "Now note the change in bulk"! Item was added: + ----- Method: MinesBoard>>resetBoard: (in category 'initialization') ----- + resetBoard: aLevel + + boardSize := BoardSizes at: aLevel. + columns := self preferredColumns. + rows := self preferredRows. + flashCount := 0. + "" + self extent: self protoTile extent * (columns @ rows). + self adjustTiles. + + gameStart := false. + gameOver := false. + + flashCount := 0. + tileCount := 0. + Collection initialize. "randomize the Collection class" + self purgeAllCommands. + self submorphsDo: "set tiles to original state." + [:m | m privateOwner: nil. "Don't propagate all these changes..." + m mineFlag: false. + m disabled: false. + m switchState: false. + m isMine: false. + m privateOwner: self]. + self changed "Now note the change in bulk"! Item was changed: ----- Method: MinesBoard>>stepOnTile: (in category 'actions') ----- stepOnTile: location + | mines tile score | - | mines tile | tile := self tileAt: location. tile mineFlag ifFalse:[ tile isMine ifTrue: [tile color: Color gray darker darker. self blowUp. ^false.] ifFalse:[ mines := self findMines: location. tile switchState: true. tileCount := tileCount + 1. mines = 0 ifTrue: [self selectTilesAdjacentTo: location]]. + tileCount = ((columns*rows) - self preferredMines) ifTrue:[ gameOver := true. flashCount := 2. owner timeDisplay stop. + score := owner timeDisplay value. + ( score < (boardSize at:4)) + ifTrue:[(BoardSizes at: owner level ) at: 4 put: score. + owner hiScoreDisplay value: score]]. - tileCount = ((columns*rows) - self preferredMines) ifTrue:[ gameOver := true. flashCount := 2. owner timeDisplay stop.]. ^ true.] ifTrue: [^ false.] ! |
Free forum by Nabble | Edit this page |