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
main.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 "mbed.h" |
fomartin | 0:75716bd37804 | 3 | |
fomartin | 0:75716bd37804 | 4 | //button setup using PinDetect |
fomartin | 0:75716bd37804 | 5 | // button is pushed -> false |
fomartin | 0:75716bd37804 | 6 | // button is not pushed -> true |
fomartin | 0:75716bd37804 | 7 | PinDetect P1_LeftButton(p15, PullUp); |
fomartin | 0:75716bd37804 | 8 | PinDetect P1_RightButton(p16, PullUp); |
fomartin | 0:75716bd37804 | 9 | PinDetect P2_LeftButton(p26, PullUp); |
fomartin | 0:75716bd37804 | 10 | PinDetect P2_RightButton(p29, PullUp); |
fomartin | 0:75716bd37804 | 11 | |
fomartin | 0:75716bd37804 | 12 | //LCD setup |
fomartin | 0:75716bd37804 | 13 | uLCD_4DGL uLCD(p28, p27, p21); // serial tx, serial rx, reset pin; |
fomartin | 0:75716bd37804 | 14 | |
fomartin | 0:75716bd37804 | 15 | //speaker setup |
fomartin | 0:75716bd37804 | 16 | AnalogOut speaker(p18); |
fomartin | 0:75716bd37804 | 17 | wave_player waver(&speaker); |
fomartin | 0:75716bd37804 | 18 | |
fomartin | 0:75716bd37804 | 19 | //states enum |
fomartin | 0:75716bd37804 | 20 | enum StateType{MainMenu, HowTo, SinglePlayerGame, TwoPlayerGame, EndScreen}; |
fomartin | 0:75716bd37804 | 21 | StateType state = MainMenu; |
fomartin | 0:75716bd37804 | 22 | |
fomartin | 0:75716bd37804 | 23 | |
fomartin | 0:75716bd37804 | 24 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
fomartin | 0:75716bd37804 | 25 | |
fomartin | 0:75716bd37804 | 26 | //member variables |
fomartin | 0:75716bd37804 | 27 | int option; |
fomartin | 0:75716bd37804 | 28 | int points; |
fomartin | 0:75716bd37804 | 29 | |
fomartin | 0:75716bd37804 | 30 | DigitalOut led1(LED1); |
fomartin | 0:75716bd37804 | 31 | |
fomartin | 0:75716bd37804 | 32 | main() |
fomartin | 0:75716bd37804 | 33 | { |
fomartin | 0:75716bd37804 | 34 | Music music(waver); |
fomartin | 0:75716bd37804 | 35 | |
fomartin | 0:75716bd37804 | 36 | //LCD setup |
fomartin | 0:75716bd37804 | 37 | uLCD.display_control(PORTRAIT_R); |
fomartin | 0:75716bd37804 | 38 | uLCD.baudrate(BAUD_3000000); //jack up baud rate to max for fast display |
fomartin | 0:75716bd37804 | 39 | uLCD.background_color(BLACK); |
fomartin | 0:75716bd37804 | 40 | uLCD.cls(); |
fomartin | 0:75716bd37804 | 41 | |
fomartin | 0:75716bd37804 | 42 | music.playMainMusic(); |
fomartin | 0:75716bd37804 | 43 | |
fomartin | 0:75716bd37804 | 44 | while(true) |
fomartin | 0:75716bd37804 | 45 | { |
fomartin | 0:75716bd37804 | 46 | switch(state) |
fomartin | 0:75716bd37804 | 47 | { |
fomartin | 0:75716bd37804 | 48 | case(MainMenu): |
fomartin | 0:75716bd37804 | 49 | { |
fomartin | 0:75716bd37804 | 50 | // Set-Up Main Menu |
fomartin | 0:75716bd37804 | 51 | Startup startup(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton); |
fomartin | 0:75716bd37804 | 52 | //startup.scores(uLCD, sd); |
fomartin | 0:75716bd37804 | 53 | option = startup.select(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, music); |
fomartin | 0:75716bd37804 | 54 | if(option == 0) |
fomartin | 0:75716bd37804 | 55 | state = SinglePlayerGame; |
fomartin | 0:75716bd37804 | 56 | if(option == 1) |
fomartin | 0:75716bd37804 | 57 | state = TwoPlayerGame; |
fomartin | 0:75716bd37804 | 58 | if(option == 2) |
fomartin | 0:75716bd37804 | 59 | state = HowTo; |
fomartin | 0:75716bd37804 | 60 | break; |
fomartin | 0:75716bd37804 | 61 | } |
fomartin | 0:75716bd37804 | 62 | case(HowTo): |
fomartin | 0:75716bd37804 | 63 | { |
fomartin | 0:75716bd37804 | 64 | Rules rules(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton); |
fomartin | 0:75716bd37804 | 65 | state = MainMenu; |
fomartin | 0:75716bd37804 | 66 | break; |
fomartin | 0:75716bd37804 | 67 | } |
fomartin | 0:75716bd37804 | 68 | case(SinglePlayerGame): |
fomartin | 0:75716bd37804 | 69 | { |
fomartin | 1:4976bbb3376f | 70 | //after gameplay returns, we can use gameplay.getWinningPlayer() to find out who won. |
fomartin | 1:4976bbb3376f | 71 | //this gets passed to the GameOver to display the correct winner on the screen |
fomartin | 0:75716bd37804 | 72 | Gameplay gameplay(uLCD, 1, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton); |
fomartin | 0:75716bd37804 | 73 | GameOver gameover(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, gameplay.getWinningPlayer()); |
fomartin | 0:75716bd37804 | 74 | state = MainMenu; |
fomartin | 0:75716bd37804 | 75 | break; |
fomartin | 0:75716bd37804 | 76 | } |
fomartin | 0:75716bd37804 | 77 | case(TwoPlayerGame): |
fomartin | 0:75716bd37804 | 78 | { |
fomartin | 0:75716bd37804 | 79 | Gameplay gameplay(uLCD, 2, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton); |
fomartin | 0:75716bd37804 | 80 | GameOver gameover(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, gameplay.getWinningPlayer()); |
fomartin | 0:75716bd37804 | 81 | state = MainMenu; |
fomartin | 0:75716bd37804 | 82 | break; |
fomartin | 0:75716bd37804 | 83 | } |
fomartin | 0:75716bd37804 | 84 | }//end switch |
fomartin | 0:75716bd37804 | 85 | }//end while |
fomartin | 0:75716bd37804 | 86 | }//end main |