[squeak-dev] The Trunk: EToys-ct.480.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Jan 11 14:41:06 UTC 2023
Marcel Taeumel uploaded a new version of EToys to project The Trunk:
http://source.squeak.org/trunk/EToys-ct.480.mcz
==================== Summary ====================
Name: EToys-ct.480
Author: ct
Time: 25 August 2022, 3:37:47.639239 pm
UUID: a19ea955-73d9-334b-80c2-c8a6817f9f4f
Ancestors: EToys-ct.479
Proposal: Improves state indication in Tetris game. Makes the pause button stateful. When the game is over, change the status display to red.
=============== Diff against EToys-ct.479 ===============
Item was changed:
AlignmentMorph subclass: #Tetris
+ instanceVariableNames: 'board scoreDisplay pauseSwitch'
- instanceVariableNames: 'board scoreDisplay'
classVariableNames: ''
poolDictionaries: ''
category: 'Etoys-Squeakland-Morphic-Games'!
!Tetris commentStamp: '<historical>' prior: 0!
This is a port of JTetris.java 1.0.0.
How to start:
choose new morph.../Games/Tetris
How to play:
1) using buttons
2) using keyboard:
drop - spacebar
move to left - left arrow
move to right - right arrow
rotate clockwise - up arrow
rotate anticlockwise - down arrow
NOTE: mouse must be over Tetris!
Item was added:
+ ----- Method: Tetris>>buildSwitchTarget:label:selector:help: (in category 'initialization') -----
+ buildSwitchTarget: aTarget label: aLabel selector: aSelector help: aString
+
+ ^self rowForButtons
+ addMorph: (
+ SimpleSwitchMorph new
+ target: aTarget;
+ label: aLabel;
+ actionSelector: aSelector;
+ borderStyle: (BorderStyle raised width: 2 px);
+ color: color
+ )!
Item was changed:
----- Method: Tetris>>initialize (in category 'initialization') -----
initialize
"initialize the state of the receiver"
super initialize.
""
board := TetrisBoard new game: self.
+ board addDependent: self.
self listDirection: #topToBottom;
wrapCentering: #center;
vResizing: #shrinkWrap;
hResizing: #shrinkWrap;
layoutInset: 3 px;
addMorphBack: self makeGameControls;
addMorphBack: self makeMovementControls;
addMorphBack: self showScoreDisplay;
addMorphBack: board.
+ board newGame.
+
+ self updateGameOver.!
- board newGame!
Item was added:
+ ----- Method: Tetris>>isGameOver (in category 'testing') -----
+ isGameOver
+
+ ^ board isGameOver!
Item was changed:
----- Method: Tetris>>makeGameControls (in category 'initialization') -----
makeGameControls
^ self rowForButtons
addMorph: (self
buildButtonTarget: self
label: 'Quit' translated
selector: #delete
help: 'quit' translated);
+ addMorph: (pauseSwitch := (self
+ buildSwitchTarget: self
- addMorph: (self
- buildButtonTarget: self
label: 'Pause' translated
selector: #pause
+ help: 'pause' translated) firstSubmorph) owner;
- help: 'pause' translated);
addMorph: (self
buildButtonTarget: self
label: 'New game' translated
selector: #newGame
help: 'new game' translated)!
Item was changed:
----- Method: Tetris>>pause (in category 'actions') -----
pause
+ board pause.
+ pauseSwitch setSwitchState: self paused.!
- board pause.!
Item was added:
+ ----- Method: Tetris>>paused (in category 'testing') -----
+ paused
+
+ ^ board paused!
Item was added:
+ ----- Method: Tetris>>update: (in category 'updating') -----
+ update: what
+
+ what = #paused ifTrue:
+ [pauseSwitch setSwitchState: self paused].
+ what = #isGameOver ifTrue:
+ [self updateGameOver].
+
+ ^ super update: what!
Item was added:
+ ----- Method: Tetris>>updateGameOver (in category 'events') -----
+ updateGameOver
+
+ scoreDisplay color: (self isGameOver ifTrue: [Color red] ifFalse: [Color green]).!
Item was added:
+ ----- Method: TetrisBoard>>basicGameOver: (in category 'accessing') -----
+ basicGameOver: aBoolean
+
+ gameOver := aBoolean.
+ self changed: #isGameOver.!
Item was added:
+ ----- Method: TetrisBoard>>basicPaused: (in category 'accessing') -----
+ basicPaused: aBoolean
+
+ paused := aBoolean.
+ self changed: #paused.!
Item was added:
+ ----- Method: TetrisBoard>>isGameOver (in category 'testing') -----
+ isGameOver
+
+ ^ gameOver!
Item was changed:
----- Method: TetrisBoard>>newGame (in category 'button actions') -----
newGame
self removeAllMorphs.
+ self basicGameOver: false.
+ self basicPaused: false.
- gameOver := paused := false.
delay := 500.
currentBlock := nil.
self score: 0.
!
Item was changed:
----- Method: TetrisBoard>>pause (in category 'button actions') -----
pause
gameOver ifTrue: [^ self].
+ self basicPaused: self paused not.!
- paused := paused not.
- !
Item was added:
+ ----- Method: TetrisBoard>>paused (in category 'testing') -----
+ paused
+
+ ^ paused!
Item was changed:
----- Method: TetrisBoard>>storePieceOnBoard (in category 'other') -----
storePieceOnBoard
currentBlock submorphs do: [ :each |
self addMorph: each.
((each top - self top) // self cellSize y) < 3 ifTrue: [
+ self basicPaused: true.
+ self basicGameOver: true.
- paused := gameOver := true.
].
].
currentBlock delete.
currentBlock := nil.
self checkForFullRows.
self score: score + 10.
delay := delay - 2 max: 80.
!
More information about the Squeak-dev
mailing list
|