ELEC2645 (2017/18) / Mbed 2 deprecated ll13jrm

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JRM1986
Date:
Wed Mar 21 13:09:20 2018 +0000
Parent:
6:f3f508cea1c4
Child:
8:a2b431b9b3f7
Commit message:
Initialisation of Food class completed, de-bugged but not tested with testing class;

Changed in this revision

Food/Food.cpp Show annotated file Show diff for this revision Revisions of this file
Food/Food.h Show annotated file Show diff for this revision Revisions of this file
SnakeEngine/SnakeEngine.cpp Show annotated file Show diff for this revision Revisions of this file
SnakeEngine/SnakeEngine.h Show annotated file Show diff for this revision Revisions of this file
Testing/Testing.cpp Show annotated file Show diff for this revision Revisions of this file
Testing/Testing.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
--- a/Food/Food.cpp	Fri Mar 16 13:02:55 2018 +0000
+++ b/Food/Food.cpp	Wed Mar 21 13:09:20 2018 +0000
@@ -10,12 +10,10 @@
 {
 
 }
-
-Vector2D Food::get_position()
+void Food::init(int pos_x, int pos_y)
 {
-    Vector2D p = {_x,_y};
-    
-    return p;
+  _x = pos_x;
+  _y = pos_y;    
 }
 
 void Food::set_position(Vector2D p) 
@@ -30,6 +28,15 @@
        
 }
 
+Vector2D Food::get_position()
+{
+    Vector2D p = {_x,_y};
+    
+    return p;
+}
+
+
+
 void Food::draw(N5110 &lcd) {
 
     lcd.setPixel(_x,_y,true);
--- a/Food/Food.h	Fri Mar 16 13:02:55 2018 +0000
+++ b/Food/Food.h	Wed Mar 21 13:09:20 2018 +0000
@@ -20,7 +20,7 @@
     Food(); // constructor
     ~Food(); // destructor
     
-    void init(Vector2D ip);
+    void init(int pos_x, int pos_y);
     void update();
     
     Vector2D get_position(); // returns the position of the food
--- a/SnakeEngine/SnakeEngine.cpp	Fri Mar 16 13:02:55 2018 +0000
+++ b/SnakeEngine/SnakeEngine.cpp	Wed Mar 21 13:09:20 2018 +0000
@@ -9,4 +9,12 @@
 SnakeEngine::~SnakeEngine()
 {
 
+}
+
+void SnakeEngine::init(int food_pos_x, int food_pos_y)
+{
+    _fx = food_pos_x;
+    _fy = food_pos_y;
+    
+    _food.init(_fx,_fy);
 }
\ No newline at end of file
--- a/SnakeEngine/SnakeEngine.h	Fri Mar 16 13:02:55 2018 +0000
+++ b/SnakeEngine/SnakeEngine.h	Wed Mar 21 13:09:20 2018 +0000
@@ -21,7 +21,7 @@
     SnakeEngine(); // constructor
     ~SnakeEngine(); // destructor
     
-    void init(Vector2D food_position); // initiallises the position of the food, and snake 
+    void init(int food_pos_x, int food_pos_y); // initiallises the position of the food, and snake 
     void draw(N5110 &lcd); // draws snake/food to the lcd
     void update(Gamepad &pad); // updates depending on gamepad input
     void get_input(Gamepad &pad); // gets the input from the gamepad
--- a/Testing/Testing.cpp	Fri Mar 16 13:02:55 2018 +0000
+++ b/Testing/Testing.cpp	Wed Mar 21 13:09:20 2018 +0000
@@ -12,10 +12,11 @@
 
 // ----- Food Class Tests -----
 
-Test_Cases Testing::set_food_positions() 
+void Testing::set_food_positions(TestCases t) 
 {
-    Test_Cases t;
+    //TestCases t = {_ax, _ay, _bx, _by, _cx, _cy,};
     Food food;
+    
     Vector2D p = food.get_position();
     
     int i;
@@ -26,49 +27,54 @@
             
             case 0:
             
-            t.ax = p.x;
-            t.ay = p.y;
+            _ax = p.x;
+            _ay = p.y;
             
             break;
             
             case 1: 
             
-            t.bx = p.x;
-            t.by = p.y;
+            _bx = p.x;
+            _by = p.y;
 
             break;
             
             case 2:
             
-            t.cx = p.x;
-            t.cy = p.y;
+            _cx = p.x;
+            _cy = p.y;
             
             break;
             
             default:
             
-            t.ax = 85;
-            t.ay = 49;
+            _ax = 85;
+            _ay = 49;
          
-            t.bx = t.ax;
-            t.cx = t.bx;
-            t.by = t.ay;
-            t.cy = t.by;
+            _bx = _ax;
+            _cx = _bx;
+            _by = _ay;
+            _cy = _by;
             
             break;          
             
             }
             
             }
-            
-            return t;
-            
+                        
 }
 
+TestCases Testing::get_test_cases() 
+{
+    TestCases t = {_ax, _ay, _bx, _by, _cx, _cy,};
+    
+    return t;
+}    
+
 bool Testing::food_test_position() 
 {
                 
-    Test_Cases t;
+    TestCases t;
             
         bool success_flag = false;
             
@@ -91,7 +97,7 @@
 
 bool Testing::food_test_range()
 {
-    Test_Cases t;
+    TestCases t;
         
      bool success_flag = false;
 
--- a/Testing/Testing.h	Fri Mar 16 13:02:55 2018 +0000
+++ b/Testing/Testing.h	Wed Mar 21 13:09:20 2018 +0000
@@ -45,7 +45,7 @@
     }
     */
 
-struct Test_Cases 
+struct TestCases 
 {
   
     int ax;
@@ -72,7 +72,8 @@
     
 // ----- Food Tests -----
 
-Test_Cases set_food_positions(); // stores variables for comparison in testing
+void set_food_positions(TestCases t); // stores variables for comparison in testing
+TestCases get_test_cases();
 bool food_test_position(); // tests whether variables are changing (pseudo randomly)
 bool food_test_range(); // test if variables are within range of screen pixel dimensions 48*84
 
@@ -83,7 +84,13 @@
 // ----- SnakeEngine Tests ----- 
     
 private:
-
+    
+    int _ax;
+    int _ay;
+    int _bx;
+    int _by;
+    int _cx;
+    int _cy;
 
 };
 
--- a/main.cpp	Fri Mar 16 13:02:55 2018 +0000
+++ b/main.cpp	Wed Mar 21 13:09:20 2018 +0000
@@ -5,6 +5,9 @@
 #include "Testing.h"
 #include "SnakeEngine.h"
 
+#define FOOD_X 10
+#define FOOD_Y 10
+
 struct UserInput 
 {
     
@@ -14,8 +17,7 @@
 
 /*
 ELEC2645 Embedded Systems Project
-School 
-of Electronic & Electrical Engineering
+School of Electronic & Electrical Engineering
 University of Leeds
 Name: Joshua Robert Marshall
 Username: ll13jrm
@@ -39,38 +41,11 @@
 
 int main() {
     
-        // ----- Testing Program -----
-    while(1){
+    while(1) {
         
-  
-    if(test.food_test_position()) {
-        
-        printf("Passed position test \n");
+        printf("Nothing");
         
         }
-        
-        else {
-            
-            printf("Failed position test \n");
-            
-            }
-        
-        if(test.food_test_range()) {
-            
-            printf("Passed Range Test \n");
-            
-            }
-            
-            else {
-                
-                printf("Failed Range Test \n");
-                
-                }
-
-    wait(1.0); 
-    
-    }
-
     }
     
 // initialies all classes and libraries
@@ -81,7 +56,7 @@
     pad.init();
      
     // initialise the game with food, snake...
-    // snake_engine.init(        );
+    snake_engine.init(FOOD_X, FOOD_Y);
 
 }