Deutsch English |
GAME DESCRIPTION |
|
STEP 1: GENERATING RANDOM SEQUENCE OF 0 AND 1 |
First write a program which defines the function createSeg(n) that fills n random numbers 0 or 1 in the list seq. Test the program with different n. Use the following template: Program: from microbit import * from random import randint def createSeq(n): ... seq = [] n = 3 createSeq(n) print(seq) |
STEP 2: GENERATING RANDOM SEQUENCE OF ARROWS |
The functions left() displays a left arrow (image ARROW_E ) for 500 ms and then clears the display. Write this function and test it with a small test program. |
STEP 3: IMPLEMENTING USER PLAYBACK |
Now you implement the user interaction. When the user presses the left button, the number 0 is appended in the list seg2, when the right button is pressed, the number 1 is appended. Use the following template: n = 3 seg2 = [] while len(seq2) < n: if button_a.was_pressed(): seq2.append(0) if button_b.was_pressed(): seq2.append(1) sleep(10) sleep(10) prevents the program from wasting processing time in the repeat loop (which makes it hard to break off). Complete the template so that an arrow is shown when a button is pressed. Extend the program by comparing the two lists seq and seq2. If they are the same, the playback is correct, otherwise the game is over. To give a user feedback, you can display the images YES or NO.. if seq == seq2:
display.show(Image.YES)
...
|
STEP 4: INCREASING THE DIFFICULTY LEVEL |
So far, the sequence has still the fixed length 3. Now step you begin the game with n = 2 and increase the length of the sequence by 1, if the answer is correct. |
STEP 5: HANDLING END OF GAME |
Finish the program by stopping the main loop when the game is over. It is common to use a boolean flag gameOver that is True, when the main loop has to be terminated. Use the following template: .... It is nice to show the length of the last sequence as a scrolling text (the game score). You can restart the game any time by pressing the reset button.
|
STEP 6: EXPANDING THE GAME TO OWN IDEAS |
You certainly have many ideas on how to customize or enhance the game.
|