Develop your first game | How to create an app without coding or programming skills | Thunkable
You want to create a new Android Application. Maybe you are already a developer and you want a professional application in no time or you have No Idea of Programming but you have a dream to create your first app. In both cases, you have come to the right place.
In the previous video, we have already started working on our first application in Thunkable.
In this video, we will start the fun part, by developing the functionalities of our app.
You can Watch the coding part in the VIDEO above from 0:52
As you can remember this is our first screen. So this is the first thing that the user will see. The only thing that we should implement is the connection of the first page with the actual game.
First, we will go to Blocks. Here we can see the functionality of the Button 1. The goal here is when the user presses the button1 to change the screen and go to the game. So we can use the first block and then we will go to the control in order to change something in the system and we will choose open another screen. Finally, we will write what screen we want to open. So we will use text. And more specifically the first one. And we will write Game, which is the name of the second screen.
At this point, we can test the functionality. We will use again the live test by using the Thunkable app. And if we press the button here, we will go to the next screen as was planned.
Now we will start the development of the actual game. First, we need a strategy. It is easier if we transform the 3 options into numbers. So from now on 1 is scissors 2 is paper and 3 is rock.
Every time that a new game starts, the user will choose one of the numbers and the computer will choose one of the numbers randomly, in order to create a simple app.
Now we should set up the rules of the game. As you can understand in the case of scissors (1) and paper (2) the scissors (1) wins. Also if we have 2 and 3 the 2 wins. Finally if, we have 1 and 3 the 3 wins.
We will name the variable of Player Pl and the variable of Computer Cp. And the results of the game Res with 1 if Player wins and 0 if Computer wins.
First of all, we should use the notifier. In this way, we can create a notification that shows the result of every round. Then we will start developing the blocks. First, we will initialize the variables. For that, we will go to the variables section and then initialize
Then we will start developing the blocks. First, we will initialize the variables. For that, we will go to the variables section and then initialize global variable. Then we can change the name of the player and make it equal to 0. In addition, we will copy and paste this command line for the computer variable. But here we should use a random variable for 1 to 3.
Let’s go back to the design. In the case that the user clicks the Button1, the algorithm should change the player variable into the number 2. Then it will read the Computer variable, and if it is equal to 1 he will lose. If it is 2 he will play again and if it is 3 he will win.
For the click of the first Button, we can use this command line. Then we will set the player equal to 2. As we already mentioned in the analysis we will use an if statement from the control. At this point we should compare the Cp variable with a number, so we can use a function from math and then the number 1 and the get cp variable. If this is actually true, we can use the Notifier in order to show a message to the user. More specifically, we will use this function that can show a message title and a button. For the message, we will say that you Lose from the Text. Then for the title, we will write Final Results and for the button Next.
Finally, it is really really important to set the computer variable to a new random variable!! In this way, we can play again the game.
Now we should create the other buttons. So we can copy and paste the whole code. For the Button2 we have rock so we will set the Player variable to 3. Then we will change the messages: if the computer is equal to 1 we will win, if it is 2 we will lose and so on and so forth. The same exact way of thinking can be applied to the third button.
What? Don’t we use the Player variable? This is actually true. In the final code, we don’t really need a variable of the player because that algorithm already knows the player’s choice from the button. So it is perfectly acceptable to delete this line of code.
Let’s actually try the game. As you can see, everything works perfectly.
At this point, you can see that the game that we have created is extremely simple. So now that we have created the core of the game and it is working correctly, we can make something more interesting. For example, we can show the choice of the computer instead of just showing that you lose or win. Also, we can show a counter for both the computer and the player. Finally, we can have a more intelligent opponent that evaluates the way that you play and tries to find the best possible way to win the game instead of just random numbers.
And as always, keep coding guys!