Snake Game

Dependencies:   N5110 mbed

Fork of ProjectSnake by William Smith

Revision:
1:44cc07feab7e
Parent:
0:4b8288518876
Child:
2:3389133a2223
--- a/main.cpp	Wed May 04 17:31:50 2016 +0000
+++ b/main.cpp	Wed May 04 18:24:37 2016 +0000
@@ -410,124 +410,129 @@
     } else if (joystick.direction == UP) {
         //lcd.printString("UP",20,1); // display welcome
         wait(0.05);
+        //y--;
         change = 1;
+        if
     } else if (joystick.direction == DOWN) {
         //lcd.printString("DOWN",20,1); // display welcome
         wait(0.05);
         change = 2;
+        //y++;
     } else if (joystick.direction == LEFT) {
         //lcd.printString("LEFT",20,1); // display welcome
         wait(0.05);
+        //x--;
         change = 3;
     } else if (joystick.direction == RIGHT) {
         //lcd.printString("RIGHT",20,1); // display welcome
         wait(0.05);
+        //x++;
         change = 4;
     }
-    if (change == 1) {
-        y--;
-    } else if (change == 2) {
-        y++;
-    } else if (change == 3) {
-        x--;
-    } else if (change == 4) {
-        x++;
+     if (change == 1) {
+         y--;
+     } else if (change == 2) {
+         y++;
+     } else if (change == 3) {
+         x--;
+     } else if (change == 4) {
+         x++;
+     }
+
     }
-
-}
-void SnakeGrowing()
-{
+    void SnakeGrowing() {
 
 
-    if(Score>=10) {
-        array[y+36][x+5]= 1;
+        if(Score>=10) {
+            array[y+36][x+5]= 1;
 
-        array[y1+36][x1+5]= 1;
+            array[y1+36][x1+5]= 1;
 
-        array[y2+36][x2+5]= 1;
+            array[y2+36][x2+5]= 1;
 
-        array[y3+36][x3+5]= 1;
+            array[y3+36][x3+5]= 1;
 
-        array[y4+36][x4+5]= 1;
+            array[y4+36][x4+5]= 1;
 
-        array[y5+36][x5+5]= 1;
+            array[y5+36][x5+5]= 1;
 
-        array[y6+36][x6+5]= 1;
+            array[y6+36][x6+5]= 1;
 
-    }
+        }
 
 
-    if(Score>=20) {
-        array[y+36][x+5]= 1;
+        if(Score>=20) {
+            array[y+36][x+5]= 1;
 
-        array[y1+36][x1+5]= 1;
+            array[y1+36][x1+5]= 1;
 
-        array[y2+36][x2+5]= 1;
+            array[y2+36][x2+5]= 1;
 
-        array[y3+36][x3+5]= 1;
+            array[y3+36][x3+5]= 1;
 
-        array[y4+36][x4+5]= 1;
+            array[y4+36][x4+5]= 1;
 
-        array[y5+36][x5+5]= 1;
+            array[y5+36][x5+5]= 1;
 
-        array[y6+36][x6+5]= 1;
+            array[y6+36][x6+5]= 1;
 
-        array[y7+36][x7+5]= 1;
+            array[y7+36][x7+5]= 1;
 
-        array[y8+36][x8+5]= 1;
-    }
-    if(Score>=30) {
-        array[y+36][x+5]= 1;
+            array[y8+36][x8+5]= 1;
+        }
+        if(Score>=30) {
+            array[y+36][x+5]= 1;
 
-        array[y1+36][x1+5]= 1;
+            array[y1+36][x1+5]= 1;
 
-        array[y2+36][x2+5]= 1;
+            array[y2+36][x2+5]= 1;
 
-        array[y3+36][x3+5]= 1;
+            array[y3+36][x3+5]= 1;
 
-        array[y4+36][x4+5]= 1;
+            array[y4+36][x4+5]= 1;
 
-        array[y5+36][x5+5]= 1;
+            array[y5+36][x5+5]= 1;
 
-        array[y6+36][x6+5]= 1;
+            array[y6+36][x6+5]= 1;
 
-        array[y7+36][x7+5]= 1;
+            array[y7+36][x7+5]= 1;
 
-        array[y8+36][x8+5]= 1;
+            array[y8+36][x8+5]= 1;
 
-        array[y9+36][x9+5]= 1;
+            array[y9+36][x9+5]= 1;
 
-        array[y10+36][x10+5]= 1;
+            array[y10+36][x10+5]= 1;
 
-    }
-    if(Score>=40) {
-        array[y+36][x+5]= 1;
+        }
+        if(Score>=40) {
+            array[y+36][x+5]= 1;
 
-        array[y1+36][x1+5]= 1;
+            array[y1+36][x1+5]= 1;
 
-        array[y2+36][x2+5]= 1;
+            array[y2+36][x2+5]= 1;
 
-        array[y3+36][x3+5]= 1;
+            array[y3+36][x3+5]= 1;
 
-        array[y4+36][x4+5]= 1;
+            array[y4+36][x4+5]= 1;
 
-        array[y5+36][x5+5]= 1;
+            array[y5+36][x5+5]= 1;
 
-        array[y6+36][x6+5]= 1;
+            array[y6+36][x6+5]= 1;
 
-        array[y7+36][x7+5]= 1;
+            array[y7+36][x7+5]= 1;
 
-        array[y8+36][x8+5]= 1;
+            array[y8+36][x8+5]= 1;
 
-        array[y9+36][x9+5]= 1;
+            array[y9+36][x9+5]= 1;
 
-        array[y10+36][x10+5]= 1;
+            array[y10+36][x10+5]= 1;
 
-        array[y11+36][x11+5]= 1;
+            array[y11+36][x11+5]= 1;
 
-        array[y12+36][x12+5]= 1;
+            array[y12+36][x12+5]= 1;
 
-    }
+        }
+    
     if(Score>=50) {
         array[y+36][x+5]= 1;
 
@@ -789,17 +794,30 @@
 
 /*void GameOver()
 {
-
-    if (button==1) {
-
-        lcd.clear();
+if (joystick.direction == CENTRE) {
+        //lcd.printString("CENTRE",20,1); // display welcome
+        wait(0.05);
+    } else if (joystick.direction == UP) {
+        lcd.printString("UP",20,1); // display welcome
+        wait(0.05);
+        if(y+36==2 && x+5==2) {
+        GenerateFood();
+    } else if (joystick.direction == DOWN) {
+        lcd.printString("DOWN",20,1); // display welcome
+        wait(0.05);
+        change = 2;
+        if(y+36==randY && x+5==randX) {
+        GenerateFood();
+    } else if (joystick.direction == LEFT) {
+        //lcd.printString("LEFT",20,1); // display welcome
+        wait(0.05);
+        change = 3;
+    } else if (joystick.direction == RIGHT) {
+        //lcd.printString("RIGHT",20,1); // display welcome
+        wait(0.05);
+        change = 4;
+    }
 
-        lcd.printString("Welcome",20,1); // display welcome
-        //wait(0.1);
-        lcd.printString("To",35,3); // display To the game
-        //wait(0.1);
-        lcd.printString("SNAKE",27,5);  // display of life
-        //wait(1);
     }
 }
-*/
\ No newline at end of file
+*/