Implementing the game over screen
Before sharing the game results, we should implement the game over scenario. In our case, it is probably an expensive operation. We should check all the possible moves on the stage. If there are no moves a user can make to clear the next set of color bubbles, we should notify the user that the game is finished and show the share dialog box to him. So, let's develop an algorithm to check the possible moves.
I will separate the logic into two different scenarios:
- When we check vertical identity
- When we check horizontal identity
For both scenarios, the logic is pretty much the same. Just the x and y coordinates should change in the calculations.
The vertical scenario
In the following image, you can see all the possible positions of bubbles with the same color:
Here, you can see nine different possible combinations. I displayed only three same color bubbles in each combination, because it is enough to detect the possible successful move.
Let's look at combinations...