Francisco Martin / Mbed 2 deprecated MexicanStandoff

Dependencies:   SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Rules.cpp Source File

Rules.cpp

00001 #include "States.h"
00002 #include <algorithm>
00003 
00004 
00005 /**
00006  * Displays the rules of the game to the player. The right buttons are used to scroll between instruction pages.
00007  * Either of the left buttons will return back to the Startup screen.
00008  */
00009 Rules::Rules(uLCD_4DGL &uLCD, PinDetect &button0, PinDetect &button1, PinDetect &button2, PinDetect &button3)
00010 {
00011     uLCD.color(LGREY);
00012     uLCD.set_font_size(5, 9);
00013     
00014     int page = 0;
00015     bool updateText = true;
00016     
00017     
00018     do
00019     {
00020         if(updateText)
00021         {
00022             updateText = false;
00023             
00024             switch(page)
00025             {
00026                 case 0:
00027                 {
00028                     uLCD.cls();
00029                     uLCD.printf(" Mexican Standoff \n");
00030                     uLCD.printf("  First player to \n");
00031                     uLCD.printf(" fire the correct \n");
00032                     uLCD.printf("     gun wins!    \n");
00033                     uLCD.printf("\n");
00034                     uLCD.printf(" Learn the visual \n");
00035                     uLCD.printf("       cues!      \n");
00036                     uLCD.printf("\n");
00037                     uLCD.printf("\n");
00038                     uLCD.printf("    (Page 1/2)    ");
00039                 } break;
00040                 
00041                 case 1:
00042                 {
00043                     uLCD.cls();
00044                     uLCD.printf("      Video:      \n");
00045                     uLCD.printf("  Shoot on green. \n");
00046                     uLCD.printf(" Hold fire on red.\n");
00047                     uLCD.printf(" Arrow tells which\n");
00048                     uLCD.printf("gun to use. Circle\n");
00049                     uLCD.printf(" means use either!\n");
00050                     uLCD.printf("\n");
00051                     uLCD.printf("\n");
00052                     uLCD.printf("\n");
00053                     uLCD.printf("    (Page 2/2)    ");
00054                 } break;
00055             }
00056         }
00057         
00058         //check to see if user has pressed button to scroll to next page
00059         if(!button3)
00060         {
00061             if(page != 0)
00062                 updateText = true;
00063                 
00064             page = max(0, page - 1);
00065         }    
00066         if(!button2)
00067         {
00068             if(page != 2)
00069                 updateText = true;
00070                 
00071             page = min(1, page + 1);
00072         }
00073             
00074     } while(button0 && button1); //evaluate this after rendering text so it doesn't immediately exit menu if button is down
00075 }