Simple letter game testing dexterity and using several features of the microbit, such as button events, the display and the system timer

Dependencies:   microbit

Fork of microbit-letter-game by Anna Bridge

You are viewing an older revision! See the latest version

Homepage

Simple letter game

Overview

This is a simple game which demonstrates a number of built in microbit features and some general programming ideas.

The basic idea of the game is to test hand eye coordination based on visual stimulus. After a start up sequence, a random letter from A-Z is displayed on the microbit display. The player must then determine if the letter is a vowel or a consonant and press an associated button accordingly (left for vowel, right for consonant). There is a pre-determined time limit during which the correct button must be pressed. Each time the player reaches the next level this time limit reduces. The player scores 1 point for each correct press. Once an incorrect button is pressed or the time limit exceeded, the game is over and the players score is displayed.

Start up sequence

The start up sequence consists of a scrolling message: "GET READY ...", followed by an animated shrinking then expanding box.

Levelling up

The next level is reached when the player scores a predetermined number of points. To indicate a levelling up the shrinking and expanding box animation is displayed.

Game over

Once the game is over , a scrolling message: "GAME OVER. SCORE = " is displayed.

Game mechanics

There were a number of areas to be considered when designing the game,

  • How to display a random letter
  • How to get a button press and disable presses at certain times
  • How to measure a response time
  • How to write text to the display
  • How to animate a picture on the display
  • How to allow easy configuration of difficulty level.

Random letters

The microbit has a function to print a single character:

    uBit.display.printChar(character)

Character can be a single quoted value, e.g. 'A' or the ASCII code of a character, e.g. 65 (ASCII code for 'A').

Thus to display a random character in the range A-Z we can generate a random number in the range 65 - 90 and then call the above function with that value.

The microbit has a random number generator:

uBit.random(x)

This produces a random number in the range 0 to x. However we want a value in the range 65 to 90 , thus:

char letter = uBit.random(26) + 65;
uBit.display.printChar(letter);

All wikipages