Rock Paper Scissors version 2
This is an extended version of the Rock Paper Scissors game, where two Kniwwelinos communicate with each other to give feedback who has won: the RGB LED lights up in green for the winner, in red for the loser, and in blue in case both are equal.
Programming
- Create two variables in
Kniwwelino on start
to store your score and the one of your friend:myScore
andyourScore
.
- Create a group for exchanging messages.
- Connect the variable
yourScore
to the topic used by your friend to send his/her score:GAME/friendA
.
- Each time button A is clicked, both scores are first reset to 0, and the RGB LED is switched off. Then, there is a countdown as a delay to make sure the score is not calculated before your friend has pressed the button too (and reset his scores). After that, the own score (
myScore
) is calculated randomnly and send via a message to the topicGAME/friendB
.
- As in the original version, you now check the score and display an icon on the matrix representing the rock, the paper, or the scissors.
- Finally you want to light the RGB LED in the right color. For this, you need to check the value of both scores (stored in
myScore
andyourScore
) and color it in blue (if equal), green (if you won), or red (if your friend won).
- Use the same code for the Kniwwelino of your friend, but replace
friendA
withfriendB
, and vice-versa for the topics. Your friend then attaches a variable to topicGAME/friendB
, and sends the own score to topicGAME/friendA
.
Solution
This is the entire solution for one of the players. For the second player, just replace friendA
with friendB
and vice-versa.
Open project in KniwwelinoBlockly