A color bomb piece has been added to the game as well as score calculation and GUI elements.
I wanted to add another piece popular in match 3 games - a color bomb which removes all the pieces of a certain color when switched with a regular piece (or removes all pieces if switched with another color bomb). This bomb is created by matching 5 or more pieces of the same color.
A new Color value was added to the BombType enum. Piece class also got a new method HasColorBomb() making it easy to find out if a piece has a color bomb attached. PieceManager has been expanded with a GetColorBombMatches() method which returns all the matches involved in a color bomb switch. To make it work, another method called GetPiecesOfType() was implemented which returns all the pieces of a certain type.
Integ tests and unit tests were also added to follow the changes introduced by color bomb logic. A GUI object was created to accommodate a simple score counter. To achieve a working score counter I added a few more classes: GameManager, GuiManager and the CSharpMessenger class already used in my FPS base project to make communication between components more efficient.
GameManager handles current score and a score limit (so the game can be won by reaching a target score). It listens to the AddScore event and also listens to OnBoardInitialized to avoid problems caused by score calculations during board initalization. GameManager creates the GameManager instance which has the same GameObject as parent.
AddScore event is fired in PieceManager’s AddScore() method which gets the score value from the removed piece, adds a bomb score value if it has a bomb attached and also multiplies it with a cascade multiplier. Multiplier is incremented after every consecutive match created in a single move.
If a score limit is set on the current level, a GameOverWin event is fired by GameManager upon reaching this target score along with a message to display on the GUI.
GuiManager puts all the GUI texts attached to its GameObject in a List, this way all text elements can be managed as a whole. It has a text for the score and two texts for the game over canvas group which is set to alpha 0 by default. SetScore() can be used to set the score text element’s value. Upon receiving an OnGameOverWin message it displays the game over canvas group along with the appropriate message.
Target score reached