In that tutorial, you are going to learn how to create an Anagram game for Android by using Android Studio.

But what is an Anagram ?

An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example, the word anagram can be rearranged into “nag a ram”.

Note that you can discover this tutorial in video on YouTube :

Create the User Interface

To start, we are going to create the User Interface of our Anagram game. In our User Interface, we will have a TextView to display the anagram. Then, an EditText to let the users to enter the word they found. And finally both buttons : one to validate the word entered and another to start a new game.

We make some customizations on these views. For example, we center them horizontally and this gives us the following code :

 

Core of the Anagram Game

Now, we can create the core of our game : the Anagram class. We will use this class to generate new words to find and to shuffle the word to find. Note that the list of words used for the game will be defined in this class :

 

Code of the Main Activity

Now, we can write the Java code of the main activity. The code is pretty simple. We get references of the views in the onCreate method. Then we install OnClickListener for both buttons.

In the validate method, we are going to check if the word entered by the user if equal to the word to find. If yes, we display a message of congratulations to the user and we start a new game by calling the newGame method.

The newGame method is used to start a new Anagram game. We generate a random word to find by calling the randomWord method of the Anagram class. Then, we shuffle this word via the shuffleWord method of the Anagram class. Finally, we display the word shuffled on the screen. The game starts and the user must find the word.

This gives us the following code :

 

Play to our Anagram Game

Now, it’s time to play to our Anagram Game. We launch the Anagram Game on an Android device and we see the following screen :

We have to enter the word to find in the EditText and then clicking to the validate button to win the game.

That’s all for that tutorial. To discover more tutorials on Android Development, don’t hesitate to subscribe to the SSaurel’s Channel on YouTube :