In this chapter of the Guessing Game tutorial we are going to implement the core part, which is how we can play the game. For this, we are going to create one more ViewModel. This ViewModel will contain the business logic about the game.
In the very last chapter (Guessing Game – ViewModel), we have implement a ViewModel class already, which is responsible to change the username, and store it indside of a LiveData.
First, we are going to create an enum. This enum will hold the 4 states of the game. Then, we gonna start the implementation of the GameViewModel, which will contain the business logic. It means, here we gonna generate the random numbe to guess, then compare this number to the number of the guess, show the result and start a new game. Inside of this ViewModel we gonna implement two more methods, which will help us to show and hide the soft keyboard after every guess.
So, let’s start coding! 😎