👊🏻✋🏻✌🏻 — Rock-Paper-Scissors!
Create Rock-Paper-Scissors Android Game on Sketchware!
In our previous tutorial, we introduced the concept of Random by creating a Dice application. Today, we’re going to create a simple Rock-Paper-Scissors game that will help us compare different random values! You will also learn to create a fancy A.I. that will play against you.
Here is what we’re going to create today:
What you’ll need
- Sketchware Application from Google Play
What you’ll learn
- Concept of using Random and Comparison
Step 1: Designing the Application
In this tutorial, we provide the images displayed above. It doesn’t have to look exactly the same — get creative!
Step 2: Setting up the Logic
When humans play rock paper scissor, we think before our next move; however, how do computers think? We could create the next AlphaGo, but instead, we’re going to generate a simple Random value to decide what the computer is going to give for the next move.
Here is a brief preview of our logic:
1. We select either Rock, Paper, or Scissors.
2. Computer generates a random number between 0 and 2, 0 being the Rock, 1 being the Paper, and 2 being the Scissors.
3. We compare the user input and computer value and display the outcome.
4. The user is able to repeat step 1.
We are going to treat user selection as number value — 0, 1, 2 — as well, since we need to compare the values to check who won.
This is the case when the user selects Rock. Note that all the setBackgroundColor blocks are to add a touch of User Experience — by highlighting the image the user clicked, he or she will know that the image was selected properly. We called the computer’s random value as comValue.
The logic screen for Paper and Scissors cases are very similar. The only difference is that the comparisons are different — for example, in the scissors logic tab, it would be a draw if comValue was 1.
That’s really it! Three cases to compare, on three image onClick events!
We created a simple Rock-Paper-Scissors game on Sketchware. There are, however, ways to create this application more simple and fun. So here are your challenges:
- Reduce the number of comparisons made using moreBlocks.
- Use the Timer component to create a delay before the computer makes a move, so it looks like the computer is thinking.
- Make userWin and computerWin variables, so you can keep track of how many times you or the computer won.
That’s it! Happy coding 😎✌🏻