This is the Mexican Standoff prototype made by Francisco Martin and Andrew Smith. Please refer to the following link for instructions on hardware hookup: https://developer.mbed.org/users/fomartin/notebook/mexican-standoff-reaction-game/
Dependencies: SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect
States/Rules.cpp@2:3c1a5079243d, 2016-03-14 (annotated)
- Committer:
- fomartin
- Date:
- Mon Mar 14 19:14:23 2016 +0000
- Revision:
- 2:3c1a5079243d
- Parent:
- 1:4976bbb3376f
Fixed bug with player 2 pressing button during X prompt.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fomartin | 0:75716bd37804 | 1 | #include "States.h" |
fomartin | 0:75716bd37804 | 2 | #include <algorithm> |
fomartin | 0:75716bd37804 | 3 | |
fomartin | 1:4976bbb3376f | 4 | |
fomartin | 1:4976bbb3376f | 5 | /** |
fomartin | 1:4976bbb3376f | 6 | * Displays the rules of the game to the player. The right buttons are used to scroll between instruction pages. |
fomartin | 1:4976bbb3376f | 7 | * Either of the left buttons will return back to the Startup screen. |
fomartin | 1:4976bbb3376f | 8 | */ |
fomartin | 0:75716bd37804 | 9 | Rules::Rules(uLCD_4DGL &uLCD, PinDetect &button0, PinDetect &button1, PinDetect &button2, PinDetect &button3) |
fomartin | 0:75716bd37804 | 10 | { |
fomartin | 0:75716bd37804 | 11 | uLCD.color(LGREY); |
fomartin | 0:75716bd37804 | 12 | uLCD.set_font_size(5, 9); |
fomartin | 0:75716bd37804 | 13 | |
fomartin | 0:75716bd37804 | 14 | int page = 0; |
fomartin | 0:75716bd37804 | 15 | bool updateText = true; |
fomartin | 0:75716bd37804 | 16 | |
fomartin | 0:75716bd37804 | 17 | |
fomartin | 0:75716bd37804 | 18 | do |
fomartin | 0:75716bd37804 | 19 | { |
fomartin | 0:75716bd37804 | 20 | if(updateText) |
fomartin | 0:75716bd37804 | 21 | { |
fomartin | 0:75716bd37804 | 22 | updateText = false; |
fomartin | 0:75716bd37804 | 23 | |
fomartin | 0:75716bd37804 | 24 | switch(page) |
fomartin | 0:75716bd37804 | 25 | { |
fomartin | 0:75716bd37804 | 26 | case 0: |
fomartin | 0:75716bd37804 | 27 | { |
fomartin | 0:75716bd37804 | 28 | uLCD.cls(); |
fomartin | 0:75716bd37804 | 29 | uLCD.printf(" Mexican Standoff \n"); |
fomartin | 0:75716bd37804 | 30 | uLCD.printf(" First player to \n"); |
fomartin | 0:75716bd37804 | 31 | uLCD.printf(" fire the correct \n"); |
fomartin | 0:75716bd37804 | 32 | uLCD.printf(" gun wins! \n"); |
fomartin | 0:75716bd37804 | 33 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 34 | uLCD.printf(" Learn the visual \n"); |
fomartin | 0:75716bd37804 | 35 | uLCD.printf(" cues! \n"); |
fomartin | 0:75716bd37804 | 36 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 37 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 38 | uLCD.printf(" (Page 1/2) "); |
fomartin | 0:75716bd37804 | 39 | } break; |
fomartin | 0:75716bd37804 | 40 | |
fomartin | 0:75716bd37804 | 41 | case 1: |
fomartin | 0:75716bd37804 | 42 | { |
fomartin | 0:75716bd37804 | 43 | uLCD.cls(); |
fomartin | 0:75716bd37804 | 44 | uLCD.printf(" Video: \n"); |
fomartin | 0:75716bd37804 | 45 | uLCD.printf(" Shoot on green. \n"); |
fomartin | 0:75716bd37804 | 46 | uLCD.printf(" Hold fire on red.\n"); |
fomartin | 0:75716bd37804 | 47 | uLCD.printf(" Arrow tells which\n"); |
fomartin | 0:75716bd37804 | 48 | uLCD.printf("gun to use. Circle\n"); |
fomartin | 0:75716bd37804 | 49 | uLCD.printf(" means use either!\n"); |
fomartin | 0:75716bd37804 | 50 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 51 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 52 | uLCD.printf("\n"); |
fomartin | 0:75716bd37804 | 53 | uLCD.printf(" (Page 2/2) "); |
fomartin | 0:75716bd37804 | 54 | } break; |
fomartin | 0:75716bd37804 | 55 | } |
fomartin | 0:75716bd37804 | 56 | } |
fomartin | 0:75716bd37804 | 57 | |
fomartin | 1:4976bbb3376f | 58 | //check to see if user has pressed button to scroll to next page |
fomartin | 0:75716bd37804 | 59 | if(!button3) |
fomartin | 0:75716bd37804 | 60 | { |
fomartin | 0:75716bd37804 | 61 | if(page != 0) |
fomartin | 0:75716bd37804 | 62 | updateText = true; |
fomartin | 0:75716bd37804 | 63 | |
fomartin | 0:75716bd37804 | 64 | page = max(0, page - 1); |
fomartin | 0:75716bd37804 | 65 | } |
fomartin | 0:75716bd37804 | 66 | if(!button2) |
fomartin | 0:75716bd37804 | 67 | { |
fomartin | 0:75716bd37804 | 68 | if(page != 2) |
fomartin | 0:75716bd37804 | 69 | updateText = true; |
fomartin | 0:75716bd37804 | 70 | |
fomartin | 1:4976bbb3376f | 71 | page = min(1, page + 1); |
fomartin | 0:75716bd37804 | 72 | } |
fomartin | 0:75716bd37804 | 73 | |
fomartin | 0:75716bd37804 | 74 | } while(button0 && button1); //evaluate this after rendering text so it doesn't immediately exit menu if button is down |
fomartin | 0:75716bd37804 | 75 | } |