Notifying game observers in newPiece() method of TetrisGame implementation

Hello,
the assignment about calling the game observers seems a little bit unclear to me, especially when it comes to the method newPiece().
In the interface it says in a comment:

Brings a new Piece into the game, informs the observers, and deletes complete rows.

My question is:
Does “inform the observers” only refer to the rowsCompleted() method of the observers, in case at least one row was removed or are we also supposed to call the piecePositionChanged() method, since technically, the piece position has changed when we insert a new piece?

Greetings
Henry

2 Likes

The newPiece method does not inform the observer of a position change as the current piece itself does not change its position but is rather replaced with a new piece.

Note:
If in doubt, you can (as for the URI project) write tests against our reference implementations in tetris.tests.
A test for the observer events you could write might look something like:

	@Test
	public void testNewPieceObserver() {
		TetrisGame game = MyTetrisFactory.createTetrisGame(new Random());
		var observer = new LoggingObserver();
		game.addObserver(observer);
		game.newPiece();
		assertEquals(0,observer.getPiecePositionChangedCount());
		game.step();
		assertEquals(1,observer.getPiecePositionChangedCount());
	}
1 Like