Monthly Members’ Competition

Competition Date:  10 to 16 Aug 2020

Tug Of War

Sensors used:
LCD RGB Backlight
Button at Port D2
Button at Port D3  

 

Program Description

Create a game of Tug-of-War for 2 players.

Player 2 will use button at D2 and Player 2 will use button at D3

The LCD will display “Ready” for 3 seconds and start the game.

Each player will try to press as quickly as possible to to win the game.

The LCD will display a counter starting at 0.

The rules are as follows:

– If only button D2 is detected, the counter will decrease by 1

– If only button D3 is detected, the counter will increase by 1

– If both buttons are pressed together, there is no change in the counter

– The counter will not count if any player holds on to a button without releasing-

The LCD will display the counter value at 0.1 second interval

– Player 1 will win when the counter reaches -5

– Player 2 will win when the counter reaches +5

– Display the winner when a player wins and end the game

Hints

Awards

5 Coins

Create the program as described above

10 Coins

Instead of displaying the value of the counter, display “100000*000002”

The * will move towards 1 as player 1 scores a point and towards 2 if player 2 scores a point

The game ends when it reaches a player, that is, “1*00000000002” or “10000000000*2”.

 

Rules

Students can try the competition question at their own time or spend up to 30 minutes of each lesson.

Instructors will only tell them if their answers are right or wrong.

No help or other comments regarding the solution will be given.

Students can try both the 5-coins and 10-coins version.

If both answers are correct, only 10-coins will be awarded.

Submissions will only be done during student’s lesson where the instructor can mark.