GameObserver work

I’m wondering how can i tell the observer of what happen in each function? I don’t really understand how the GameObserver works.

The GameObservers are generally quite simple in design.

There are 4 ‘events’ that the game observers should be informed about, that are:

  • Game Over gameOver()
  • Piece landed pieceLanded()
  • Piece Position Changed piecePositionChanged()
  • Rows Completed rowsCompleted()

and it’s as simple as it sounds, when one of these events occurs, the associated Observer method is called.

Example:

Your current piece is moved to the left → your game implementation calls the piecePositionChanged() method from the Game Observer.

Please note that it should be possible to add more than one observer to a game, e.g. one for the AutoPlayer and one for the user interface.

This post could also be interesting for you

2 Likes