Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Revision:
12:1c0b6796aaca
Parent:
11:ab578a151f67
Child:
13:12276eed13ac
--- a/Spaceship/Spaceship_test.h	Thu Apr 23 18:17:28 2020 +0000
+++ b/Spaceship/Spaceship_test.h	Fri Apr 24 19:09:22 2020 +0000
@@ -1,48 +1,43 @@
 #ifndef SPACESHIP_TEST_H
 #define SPACESHIP_TEST_H
 
-
-
 /** Spaceship Test
-@brief Checks Spcaceship goes to the correct postion when moved 
+@brief Checks Spcaceship goes to the correct postion when moved and doesnt go of map
 @author Benjamin Evans, University of Leeds
 @date April 2020
 @return true if test are passed 
 */
 
 bool spaceship_movement_test(){
+    // Objects reqired for test 
     Gamepad pad;
     N5110 lcd;
     Spaceship spaceship;
-    Serial usb(USBTX, USBRX); 
+    Serial usb(USBTX, USBRX);
+   
+    // Flag to return if test passed
+    bool pass_flag = true;
     
     // Initialise spaceship in start postion of 36, 22 and draw
-    
     pad.init();
     lcd.init();
     spaceship.init(); 
     spaceship.draw(lcd);
     
-    // Checks start spaceship postion 
+    // Reads start spaceship postion 
     int start_x_postion = spaceship.get_position_x_spaceship();
     int start_y_postion = spaceship.get_position_y_spaceship();
     usb.printf("start postion x = %d, start postion y = %d\n",start_x_postion, start_y_postion );
     
-    // Moves spaceship: Joystick in NE postion so should move x++, y--
+// Test Moves spaceship: Joystick in NE postion so should move x++, y--
     usb.printf("Move joystick to NE position\n");
     wait(3); // give me time to move joystick
     spaceship.movement(pad);
     
-    // Redraws spaceship
-    spaceship.draw(lcd);
-    
-    // Checks end spaceship postion
-    int end_x_postion = spaceship.get_position_x_spaceship();
-    int end_y_postion = spaceship.get_position_y_spaceship();
-    usb.printf("end postion x = %d, end postion y = %d\n",end_x_postion, end_y_postion );
-    
-    // Check if finish x,y postions are correct
-    bool pass_flag = true;
+    // Reads end spaceship postion one
+    int end_x_postion_one = spaceship.get_position_x_spaceship();
+    int end_y_postion_one = spaceship.get_position_y_spaceship();
+    usb.printf("end postion one x = %d, end postion one y = %d\n",end_x_postion_one, end_y_postion_one);
     
     // Fail test if start postision is incorrect
     if (start_x_postion != 36 || start_y_postion != 22) {
@@ -50,7 +45,37 @@
     }
     
     // Fail test if end postision is incorrect
-    if (end_x_postion != 37 || end_y_postion != 21) {
+    if (end_x_postion_one != 37 || end_y_postion_one != 21) {
+        pass_flag = false;
+    }
+    
+// Test spaceship off screen checker and spaceship is drawn: Hold Joystick in NE postion so should move x++, y--
+    usb.printf("Move joystick to NE position\n");
+    wait(3); // give me time to move joystick
+    
+    // Move spaceship to max postions 
+    for (int i = 0; i < 21;i++){
+        spaceship.movement(pad);
+    }
+    
+    // Redraws spaceship, spaceship.draw calls off screen checker 
+    spaceship.draw(lcd);
+  
+    // Reads end spaceship postion two
+    int end_x_postion_two = spaceship.get_position_x_spaceship();
+    int end_y_postion_two = spaceship.get_position_y_spaceship();
+    usb.printf("end postion two x = %d, end postion two y = %d\n",end_x_postion_two, end_y_postion_two);
+    
+    //Checks if spaceships draws 
+    int did_spaceship_draw = lcd.getPixel(end_x_postion_two,end_y_postion_two);
+    
+    // Fail test if pixel isnt drawn
+    if (!did_spaceship_draw) {
+        pass_flag = false;
+    }
+    
+    // Fail test if end postision is incorrect
+    if (end_x_postion_two != 52 || end_y_postion_two != 1) {
         pass_flag = false;
     }