Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
83:329da564799a
Parent:
80:51ca38c5dcdf
Child:
85:d50ba0994676
diff -r c51ae8a501d1 -r 329da564799a MenuClasses/Tutorial/Tutorial.cpp
--- a/MenuClasses/Tutorial/Tutorial.cpp	Mon May 06 10:49:50 2019 +0000
+++ b/MenuClasses/Tutorial/Tutorial.cpp	Mon May 06 14:28:35 2019 +0000
@@ -206,29 +206,36 @@
     {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
 };
 
-void Tutorial::Implement(N5110 &lcd, Gamepad &pad)
+
+void Tutorial::init(N5110 *lcd, Gamepad *pad)
+{
+    _lcd = lcd;
+    _pad = pad;
+}
+
+void Tutorial::Implement()
 {
     //Only executed if back is not pressed. Takes us to tutorial of how to navigate through the tutorial.
-    if(_backPressed == false) { Tutorial::gamePad(lcd, pad); }
+    if(_backPressed == false) { Tutorial::gamePad(); }
     //Only executed if back is not pressed. Takes us to tutorial of how to operate settings.
-    if(_backPressed == false) { Tutorial::settings(lcd, pad); }
+    if(_backPressed == false) { Tutorial::settings(); }
     //Only executed if back is not pressed. Takes us to tutorial of how to navigate through main menu.
-    if(_backPressed == false) { Tutorial::controlsToNavigateInMenu(lcd, pad); } 
+    if(_backPressed == false) { Tutorial::controlsToNavigateInMenu(); } 
     //Only executed if back is not pressed. Takes us to tutorial of how to navigate through mode and speed menu.
-    if(_backPressed == false) { Tutorial::controlsToNavigateGameModeSpeed(lcd,pad); }
+    if(_backPressed == false) { Tutorial::controlsToNavigateGameModeSpeed(); }
     //Only executed if back is not pressed. Takes us to tutorial of how to use in game controls and how to move snake.
-    if(_backPressed == false) { Tutorial::controlsToPlayGame(lcd, pad); }
+    if(_backPressed == false) { Tutorial::controlsToPlayGame(); }
     //Only executed if back is not pressed. Takes us to tutorial of how to navigate back and forth in menus & start or end a game..
-    if(_backPressed == false) { Tutorial::controlsForPreviousOrNext(lcd, pad); }
+    if(_backPressed == false) { Tutorial::controlsForPreviousOrNext(); }
     //RESETS _backPressed, for displaying all the tutorials if it has been selected once again in main menu.
     _backPressed = false;
 }
 
-bool Tutorial::checkBackPressed(Gamepad &pad)
+bool Tutorial::checkBackPressed()
 {
     //This is a very important process, this helps the code to not get stuck in  menu loop but also allow to toggle between diffrent menu screens.
-    if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
-        pad.tone(1000.0,0.1);
+    if (_pad->check_event(Gamepad::BACK_PRESSED) == true) {
+        _pad->tone(1000.0,0.1);
         _backPressed = true;
     } else {
         _backPressed = false;
@@ -236,124 +243,124 @@
     return _backPressed; //returns true if back is pressed, returns false otherwise.
 }
 
-void Tutorial::gamePad(N5110 &lcd, Gamepad &pad)
+void Tutorial::gamePad()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)g_pad); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Press Start or",0,4);
-        lcd.printString("A to proceed",7,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)g_pad); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Press Start or",0,4);
+        _lcd->printString("A to proceed",7,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.25);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
 
-void Tutorial::settings(N5110 &lcd, Gamepad &pad)
+void Tutorial::settings()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)Pot); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Rotate pot",12,4);
-        lcd.printString("in settings",9,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)Pot); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Rotate pot",12,4);
+        _lcd->printString("in settings",9,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.25);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
 
-void Tutorial::controlsToNavigateInMenu(N5110 &lcd, Gamepad &pad)
+void Tutorial::controlsToNavigateInMenu()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)UpDown); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Up/Down",21,4);
-        lcd.printString("for Main Menu",3,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)UpDown); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Up/Down",21,4);
+        _lcd->printString("for Main Menu",3,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.25);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
 
-void Tutorial::controlsToNavigateGameModeSpeed(N5110 &lcd, Gamepad &pad)
+void Tutorial::controlsToNavigateGameModeSpeed()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)LeftRight); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Left/Right for",0,4);
-        lcd.printString("Mode & Speed",7,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)LeftRight); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Left/Right for",0,4);
+        _lcd->printString("Mode & Speed",7,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.3);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
 
-void Tutorial::controlsToPlayGame(N5110 &lcd, Gamepad &pad)
+void Tutorial::controlsToPlayGame()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("InGameControls",0,4);
-        lcd.printString("to move snake",4,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("InGameControls",0,4);
+        _lcd->printString("to move snake",4,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.25);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Depends on",12,4);
-        lcd.printString("mode selection",0,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,31,44,(int *)GameControls); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Depends on",12,4);
+        _lcd->printString("mode selection",0,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.25);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
 
-void Tutorial::controlsForPreviousOrNext(N5110 &lcd, Gamepad &pad)
+void Tutorial::controlsForPreviousOrNext()
 {
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Previous/Next",4,4);
-        lcd.printString("End/Start",16,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Previous/Next",4,4);
+        _lcd->printString("End/Start",16,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.3);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 
-    lcd.clear();
-    while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
-        lcd.drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite.
-        lcd.drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
-        lcd.printString("Works in both",5,4);
-        lcd.printString("menu and game",5,5);
-        lcd.refresh();
+    _lcd->clear();
+    while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {  //if button pressed.
+        _lcd->drawSprite(20,0,27,44,(int *)NextBack); //Function used to draw the sprite.
+        _lcd->drawSprite(0,0,9,19,(int *)Back); //Function used to draw the back sprite.
+        _lcd->printString("Works in both",5,4);
+        _lcd->printString("menu and game",5,5);
+        _lcd->refresh();
 
-        if (Tutorial::checkBackPressed(pad)) { return; }    //if back is pressed, the function is terminated.
+        if (Tutorial::checkBackPressed()) { return; }    //if back is pressed, the function is terminated.
     }
     wait(0.3);
-    pad.tone(1000.0,0.1);
+    _pad->tone(1000.0,0.1);
 }
\ No newline at end of file