ELEC2645 (2017/18) / Mbed OS el16ajm
Revision:
3:6253a2d374fa
Parent:
2:9ca5e1c221c3
Child:
4:6353f829c56c
--- a/Snek/Snek.cpp	Mon Apr 16 10:55:00 2018 +0000
+++ b/Snek/Snek.cpp	Sun Apr 29 14:19:38 2018 +0000
@@ -16,11 +16,34 @@
     //Inital values for variables
     _x = x;
     _y = y;
+    printf ("floats: %i %i \n", _x, _y);
 }
 
 void Snek::update(Direction d)
 {
-    _direction = d;
+    if (d == N) {
+        _y -= 1;
+        _oldDirection = 'N';
+    } else if (d == S) {
+        _y += 1;
+        _oldDirection = 'S';
+    } else if (d == E) {
+        _x += 1;
+        _oldDirection = 'E';
+    }   else if (d == W) {
+        _x -= 1;
+        _oldDirection = 'W';
+    } else {
+        if (_oldDirection == 'N') {
+            _y -= 1;
+        } else if (_oldDirection == 'S') {
+            _y += 1;
+        } else if (_oldDirection == 'E') {
+            _x += 1;
+        }  else if (_oldDirection == 'W') {
+            _x -= 1;
+        }
+    }
 }
 
 int Snek::getX()