Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
UX.cpp
00001 #include "UX.h" 00002 UX::UX() 00003 { 00004 00005 } 00006 UX::~UX() 00007 { 00008 00009 } 00010 //Initialises the UX Object 00011 void UX::init() 00012 { 00013 _bat_pad.init(); 00014 _button_pressed=false; 00015 } 00016 //Resets the button_pressed variable to ensure screen is printed again 00017 void UX::reset(){ 00018 _button_pressed=false; 00019 } 00020 /*Checks if A Button is pressed to indicate if the ball is hit during the gameplay*/ 00021 int UX::get_a_pressed(){ 00022 int _a_pressed=0; 00023 if (_bat_pad.check_event(Gamepad::A_PRESSED) == true){ 00024 _a_pressed=1; 00025 } 00026 return _a_pressed; 00027 } 00028 /*Checks if L Button is pressed to indicate if the ball hit is lofted during the gameplay*/ 00029 int UX::get_l_pressed(){ 00030 int _l_pressed=0; 00031 if (_bat_pad.check_event(Gamepad::L_PRESSED) == true){ 00032 _l_pressed=1; 00033 } 00034 return _l_pressed; 00035 } 00036 /*prints the first screen labeling the game name and my student ID*/ 00037 void UX::first_menu(N5110 &menu_lcd){ 00038 menu_lcd.clear(); 00039 menu_lcd.printString("HERO CRICKET",5,1); 00040 menu_lcd.refresh(); 00041 menu_lcd.printString(" A Game By",5,2); 00042 menu_lcd.printString( " el17szs",5,3); 00043 wait(1); 00044 menu_lcd.refresh(); 00045 menu_lcd.printString("PRESS START..",1,5); 00046 wait(1); 00047 menu_lcd.refresh(); 00048 while (_bat_pad.check_event(Gamepad::START_PRESSED) == false) { 00049 printf("2"); 00050 _bat_pad.leds_on(); 00051 wait(0.1); 00052 _bat_pad.leds_off(); 00053 wait(0.1); 00054 } 00055 second_menu(menu_lcd); 00056 _bat_pad.leds_off(); 00057 } 00058 /* 00059 The second menu is called at the start of the game and each time a game is over 00060 The menu gives the user an option to choose between playing the game 00061 reading the controls or the rules of the game 00062 */ 00063 void UX::second_menu(N5110 &menu_lcd){ 00064 menu_lcd.setContrast(0.5); 00065 while (_button_pressed==false){ 00066 menu_options(menu_lcd); 00067 if (_bat_pad.check_event(Gamepad::A_PRESSED) == true){ 00068 _button_pressed=true; 00069 } 00070 if (_bat_pad.check_event(Gamepad::B_PRESSED) == true){ 00071 rules_menu(menu_lcd); 00072 } 00073 if (_bat_pad.check_event(Gamepad::X_PRESSED) == true){ 00074 controls_menu(menu_lcd); 00075 } 00076 } 00077 } 00078 /*Prints the options for the second menu onto the screen */ 00079 void UX::menu_options(N5110 &menu_lcd){ 00080 _bat_pad.leds_off(); 00081 menu_lcd.clear(); 00082 menu_lcd.setContrast(0.5); 00083 menu_lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); 00084 menu_lcd.printString("START GAME",2,1); 00085 menu_lcd.printString("A",70,1); 00086 menu_lcd.drawCircle(72,11,5,FILL_TRANSPARENT); 00087 menu_lcd.printString("RULES",2,3); 00088 menu_lcd.printString("B",70,3); 00089 menu_lcd.drawCircle(72,27,5,FILL_TRANSPARENT); 00090 menu_lcd.printString("CONTROLS",2,5); 00091 menu_lcd.printString("X",70,5); 00092 menu_lcd.drawCircle(72,42,5,FILL_TRANSPARENT); 00093 menu_lcd.refresh(); 00094 } 00095 /*Prints the rules of the game to the LCD for user experience 00096 There is wait of 5 seconds betwen each screen for the user to read the rules 00097 */ 00098 void UX::rules_menu(N5110 &menu_lcd){ 00099 rules_menu_game(menu_lcd); 00100 wait(5); 00101 rules_menu_screen_scoring_runs(menu_lcd); 00102 wait(5); 00103 rules_menu_screen_out(menu_lcd); 00104 wait(5); 00105 menu_lcd.clear(); 00106 menu_lcd.printString("The target is",0,0); 00107 menu_lcd.printString("printed bottom ",0,1); 00108 menu_lcd.printString("left of LCD",0,2); 00109 menu_lcd.printString("Balls and Runs",0,3); 00110 menu_lcd.printString("on top Right",0,4); 00111 menu_lcd.printString("and Left",0,5); 00112 menu_lcd.refresh(); 00113 wait(5); 00114 menu_lcd.clear(); 00115 menu_lcd.printString("10 balls are",0,1); 00116 menu_lcd.printString("given to score",0,2); 00117 menu_lcd.printString("a set target",0,3); 00118 menu_lcd.printString("GOOD LUCK!!!",0,4); 00119 menu_lcd.refresh(); 00120 wait(5); 00121 } 00122 /*Prints the rules for the game on the screen, called in rules_menu()*/ 00123 void UX::rules_menu_game(N5110 &menu_lcd){ 00124 menu_lcd.clear(); 00125 menu_lcd.setContrast(0.5); 00126 menu_lcd.printString("Hit the ball",0,0); 00127 menu_lcd.printString("to score runs",0,1); 00128 menu_lcd.printString("Ball is bowled",0,3); 00129 menu_lcd.printString("with a tone",0,4); 00130 menu_lcd.refresh(); 00131 wait(5); 00132 menu_lcd.clear(); 00133 menu_lcd.setContrast(0.5); 00134 menu_lcd.printString("There are 5",0,0); 00135 menu_lcd.printString("fielders in",0,1); 00136 menu_lcd.printString("the outfield ",0,2); 00137 menu_lcd.printString("marked by",0,3); 00138 menu_lcd.printString("white circles",0,4); 00139 menu_lcd.refresh(); 00140 } 00141 /*Prints the rules for scoring runs during the game*/ 00142 void UX::rules_menu_screen_scoring_runs(N5110 &menu_lcd){ 00143 menu_lcd.clear(); 00144 menu_lcd.setContrast(0.5); 00145 menu_lcd.printString("SCORING RUNS",0,0); 00146 menu_lcd.printString("Lofted Hit:",0,2); 00147 menu_lcd.printString("Hit In between ",0,3); 00148 menu_lcd.printString("the fielders ",0,4); 00149 menu_lcd.printString("is 6 runs",0,5); 00150 menu_lcd.refresh(); 00151 wait(5); 00152 menu_lcd.clear(); 00153 menu_lcd.setContrast(0.5); 00154 menu_lcd.printString("SCORING RUNS",0,0); 00155 menu_lcd.printString("Normal Hit:",0,2); 00156 menu_lcd.printString("Hit In between ",0,3); 00157 menu_lcd.printString("the fielders ",0,4); 00158 menu_lcd.printString("is 4 runs",0,5); 00159 menu_lcd.refresh(); 00160 wait(5); 00161 menu_lcd.clear(); 00162 menu_lcd.setContrast(0.5); 00163 menu_lcd.printString("SCORING RUNS",0,0); 00164 menu_lcd.printString("Normal Hit:",0,2); 00165 menu_lcd.printString("Hit to fielder ",0,3); 00166 menu_lcd.printString("inside circle ",0,4); 00167 menu_lcd.printString("is 1 run",0,5); 00168 menu_lcd.refresh(); 00169 wait(5); 00170 menu_lcd.clear(); 00171 menu_lcd.printString("SCORING RUNS",0,0); 00172 menu_lcd.printString("Normal Hit:",0,2); 00173 menu_lcd.printString("Hit to fielder ",0,3); 00174 menu_lcd.printString("out of circle ",0,4); 00175 menu_lcd.printString("is 2 runs",0,5); 00176 menu_lcd.refresh(); 00177 } 00178 /*Prints the rules for how a player can get out and lose the game */ 00179 void UX::rules_menu_screen_out(N5110 &menu_lcd){ 00180 menu_lcd.clear(); 00181 menu_lcd.printString("GETTING OUT",0,0); 00182 menu_lcd.printString("CAUGHT:",0,2); 00183 menu_lcd.printString("A Lofted Hit",0,3); 00184 menu_lcd.printString("to a fiedler",0,4); 00185 menu_lcd.printString("is OUT",0,5); 00186 menu_lcd.refresh(); 00187 wait(5); 00188 menu_lcd.clear(); 00189 menu_lcd.printString("GETTING OUT",0,0); 00190 menu_lcd.printString("BOWLED:",0,2); 00191 menu_lcd.printString("If you do ",0,3); 00192 menu_lcd.printString("not hit ball",0,4); 00193 menu_lcd.printString("It is OUT",0,5); 00194 menu_lcd.refresh(); 00195 } 00196 /*Prints the controls for the game to the LCD for user experience 00197 There is wait of 5 seconds betwen each screen for the user to read the controls 00198 */ 00199 void UX::controls_menu(N5110 &menu_lcd){ 00200 menu_lcd.clear(); 00201 menu_lcd.printString("Hold down A to ",0,2); 00202 menu_lcd.printString("hit the ball",0,3); 00203 menu_lcd.refresh(); 00204 wait(5); 00205 menu_lcd.clear(); 00206 menu_lcd.printString("Hold down A ",0,1); 00207 menu_lcd.printString("and L for ",0,2); 00208 menu_lcd.printString("a lofted hit",0,3); 00209 menu_lcd.refresh(); 00210 wait(5); 00211 menu_lcd.clear(); 00212 menu_lcd.printString("Move joystick to",0,1); 00213 menu_lcd.printString("the direction",0,2); 00214 menu_lcd.printString("you want to",0,3); 00215 menu_lcd.printString("hit the ball",0,4); 00216 menu_lcd.refresh(); 00217 wait(5); 00218 } 00219 /*Prints messages to the screen to inform user that game is over 00220 There are 3 ways for the game to end with the argument integer indicating the afformentoned. 00221 The 3 ways for the game to end are 00222 1. No more balls remaning 00223 2. Player did not hit the ball: BOWLED 00224 3. Player hit a lofted shot to a fielder : CAUGHT 00225 */ 00226 void UX::game_over_menu(N5110 &menu_lcd,int option){ 00227 if (option==1){ 00228 menu_lcd.clear(); 00229 menu_lcd.printString("GAME LOST",2,1); 00230 menu_lcd.printString("NO MORE BALLS LEFT",2,3); 00231 menu_lcd.refresh(); 00232 wait(5); 00233 } 00234 if (option==2){ 00235 menu_lcd.clear(); 00236 menu_lcd.printString("GAME LOST",2,1); 00237 menu_lcd.printString("BOWLED",2,3); 00238 menu_lcd.refresh(); 00239 wait(5); 00240 } 00241 if (option==3){ 00242 menu_lcd.clear(); 00243 menu_lcd.printString("GAME LOST",2,1); 00244 menu_lcd.printString("CAUGHT",2,3); 00245 menu_lcd.refresh(); 00246 wait(5); 00247 } 00248 } 00249 /*Prints messages to the LCD to inform user that the game is won*/ 00250 void UX::victory_menu(N5110 &menu_lcd){ 00251 menu_lcd.clear(); 00252 menu_lcd.printString("CONGRATS!!",2,1); 00253 menu_lcd.printString("YOU HAVE WON",2,3); 00254 menu_lcd.refresh(); 00255 wait(5); 00256 }
Generated on Tue Jul 19 2022 18:37:30 by
 1.7.2
 1.7.2