Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
63:205f0ca48473
Parent:
61:f3c402bc2ad0
Child:
64:540aa1602372
--- a/MenuClasses/Settings/Settings.cpp	Tue Apr 30 14:53:38 2019 +0000
+++ b/MenuClasses/Settings/Settings.cpp	Wed May 01 22:35:40 2019 +0000
@@ -2,12 +2,12 @@
 
 Settings::Settings()
 {
-    
+
 }
 
 Settings::~Settings()
 {
-    
+
 }
 
 int naviL[13][8] = {
@@ -79,48 +79,36 @@
 float * Settings::Implement(N5110 &lcd, Gamepad &pad, float cs)
 {
     Settings::info(lcd, pad);
-    int st = 1;
+    int st = 1; //an index for settings
+    wait(1/cs); //to avoid a race condition of the following while loop being skipped.
     //pad.init();
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {  //if button pressed.
         Direction d = pad.get_direction();
         wait(1/cs);
         lcd.clear();
-        
-        if((d==E)&&(st==4))  { st=1; }
-        
-        else if((d==W)&&(st==1))  { st=4; }
-        
-        else if((d==E)&&(1<=st<=3))  { st=st+1; }
-        
-        else if((d==W)&&(2<=st<=4))  { st=st-1; }
-        
+
+        if((d==E)&&(st==4))  {
+            st=1;
+        }
+
+        else if((d==W)&&(st==1))  {
+            st=4;
+        }
+
+        else if((d==E)&&(1<=st<=3))  {
+            st=st+1;
+        }
+
+        else if((d==W)&&(2<=st<=4))  {
+            st=st-1;
+        }
+
         Settings::CallFunctions(lcd, pad, st);
     }
     pad.tone(1000.0,0.1);
     return cs_sc;
 }
 
-void Settings::CallFunctions(N5110 &lcd, Gamepad &pad, int st)
-{
-    lcd.drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite.
-    lcd.drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite.
-    switch (st) {
-    case 1:
-        Settings::controlSensitivity(lcd, pad);
-        break;
-    case 2:
-        Settings::brigntness(lcd, pad);
-        break;
-    case 3:
-        Settings::contrast(lcd, pad);
-        break;
-    case 4:
-        Settings::showCredits(lcd, pad);
-        break;
-    }
-    lcd.refresh();
-}
-
 void Settings::info(N5110 &lcd, Gamepad &pad)
 {
     lcd.clear();
@@ -145,6 +133,27 @@
     lcd.clear();
 }
 
+void Settings::CallFunctions(N5110 &lcd, Gamepad &pad, int st)
+{
+    lcd.drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite.
+    lcd.drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite.
+    switch (st) {
+        case 1:
+            Settings::controlSensitivity(lcd, pad);
+            break;
+        case 2:
+            Settings::brigntness(lcd, pad);
+            break;
+        case 3:
+            Settings::contrast(lcd, pad);
+            break;
+        case 4:
+            Settings::showCredits(lcd, pad);
+            break;
+    }
+    lcd.refresh();
+}
+
 void Settings::controlSensitivity(N5110 &lcd, Gamepad &pad)
 {
     lcd.printString("Control Speeds",0,0);
@@ -181,16 +190,16 @@
     lcd.printString("Show Credits?",5,0);
     float pot;
     pot = pad.read_pot();
-    
+
     if(((0.1<=pot)&&(pot<=0.2))||((0.3<=pot)&&(pot<=0.4))||((0.5<=pot)&&(pot<=0.6))||((0.7<=pot)&&(pot<=0.8))||((0.9<=pot)&&(pot<=1)))  {
-      lcd.printString("NO",36,3);
-      cs_sc[1] = 0;
+        lcd.printString("NO",36,3);
+        cs_sc[1] = 0;
     }
-    
+
     else  {
-      lcd.printString("YES",33,3);
-      cs_sc[1] = 1;
+        lcd.printString("YES",33,3);
+        cs_sc[1] = 1;
     }
-    
+
     pad.leds_on();
 }
\ No newline at end of file