ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jiaxinZHOU
Date:
Thu May 09 02:37:14 2019 +0000
Parent:
3:ccbda43c2124
Commit message:
final

Changed in this revision

Menus/Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Menus/Menu.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
move/Move.cpp Show annotated file Show diff for this revision Revisions of this file
move/Move.h Show annotated file Show diff for this revision Revisions of this file
--- a/Menus/Menu.cpp	Wed May 08 22:18:51 2019 +0000
+++ b/Menus/Menu.cpp	Thu May 09 02:37:14 2019 +0000
@@ -147,7 +147,7 @@
             if (pad.check_event(Gamepad::A_PRESSED)) 
             {
             go_on = 1;
-            _fps = 11;
+            _fps = 12;
             }
             break;
 
--- a/Menus/Menu.h	Wed May 08 22:18:51 2019 +0000
+++ b/Menus/Menu.h	Thu May 09 02:37:14 2019 +0000
@@ -26,13 +26,13 @@
     */
     int input(int select,Gamepad &pad);
     /** 
-    * @brief initial all the parameter for the snake and food.
+    * @brief Main menu for settings and start game.
     * @param N5110 *lcd @details pointer to the N5110 object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
     * @param Gamepad *pad @details pointer to the gamepad object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
     */
     void menus(N5110 &lcd,Gamepad &pad);
     /** 
-    * @brief initial all the parameter for the snake and food.
+    * @brief select difiiculty.
     * @param N5110 *lcd @details pointer to the N5110 object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
     * @param Gamepad *pad @details pointer to the gamepad object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
     * @returns fps @details is the frame per second, with higher fps means higher difficulty.
--- a/main.cpp	Wed May 08 22:18:51 2019 +0000
+++ b/main.cpp	Thu May 09 02:37:14 2019 +0000
@@ -32,19 +32,16 @@
 
 ///////////// MAIN.CPP ////////////////
 int main () {
-    int fps = 1;
+    int fps = 0; // initial fps, fps will be update by function menu.difficulty(lcd,pad).
     initial();
     welcome();
-    menu.menus(lcd,pad);
+    menu.menus(lcd,pad);// settings or start game
     fps = menu.difficulty(lcd,pad);
     render();
-    move.getfood();
+    move.getfood(); // generate food 
     while(1) {
-    //process_input();
-    //update_game_state();
-    //refresh_display();
-    //wait_ms(1000/fps);
-    move.eatfood();
+
+    move.eatfood();  //check is food is hit by snake head, if yes , generate a new one
     move.update(pad);
     move.updatebody();
     
@@ -72,7 +69,7 @@
 
 void welcome() {
     lcd.printString("    snake!    ",0,1);  
-    lcd.printString("  Press Start ",0,4);
+    lcd.printString("( Press Start)",0,4);
     lcd.refresh();
     
         while ( pad.check_event(Gamepad::START_PRESSED) == false) {
--- a/move/Move.cpp	Wed May 08 22:18:51 2019 +0000
+++ b/move/Move.cpp	Thu May 09 02:37:14 2019 +0000
@@ -56,7 +56,7 @@
        lcd.drawRect(2*food.a, 2*food.b,2,2,FILL_BLACK);
 }
 
-
+// This function control the dirction and the movement
 void Move::update(Gamepad &pad) {
     _d = pad.get_direction();
     
@@ -90,8 +90,8 @@
         lcd.init();
             lcd.printString("Game Over",0,1);
             char buffer1[14];
-            sprintf(buffer1,"Your score:%2d",_length - 5);
-            lcd.printString(buffer1,0,2); 
+            sprintf(buffer1,"Your score:%2d",_length - 5);//As snake length will increase the same as score if one food 
+            lcd.printString(buffer1,0,2);                 //for 1 score, so i simpley use length to repersant score.
             lcd.printString("Press Start", 0 , 3);
             lcd.printString("to restart", 0 , 4);
         lcd.refresh();
@@ -103,6 +103,7 @@
         }
         initial();
         getfood();
+        menu.menus(lcd,pad);
         }
         
         for (int i =0; i < _length - 2; i++) {
@@ -124,6 +125,7 @@
                 }
             initial();
             getfood();
+            menu.menus(lcd,pad);
             }
         }
     }
--- a/move/Move.h	Wed May 08 22:18:51 2019 +0000
+++ b/move/Move.h	Thu May 09 02:37:14 2019 +0000
@@ -4,6 +4,7 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "Gamepad.h"
+#include "Menu.h"
 
 
 
@@ -74,6 +75,8 @@
     int _y;
     int _length;
     Direction _d;
+    Menu menu;
+    int _fps;
 
 };
 #endif
\ No newline at end of file