Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Spaceship/Spaceship_test.h

Committer:
evanso
Date:
2020-04-23
Revision:
11:ab578a151f67
Child:
12:1c0b6796aaca

File content as of revision 11:ab578a151f67:

#ifndef SPACESHIP_TEST_H
#define SPACESHIP_TEST_H



/** Spaceship Test
@brief Checks Spcaceship goes to the correct postion when moved 
@author Benjamin Evans, University of Leeds
@date April 2020
@return true if test are passed 
*/

bool spaceship_movement_test(){
    Gamepad pad;
    N5110 lcd;
    Spaceship spaceship;
    Serial usb(USBTX, USBRX); 
    
    // Initialise spaceship in start postion of 36, 22 and draw
    
    pad.init();
    lcd.init();
    spaceship.init(); 
    spaceship.draw(lcd);
    
    // Checks 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--
    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;
    
    // Fail test if start postision is incorrect
    if (start_x_postion != 36 || start_y_postion != 22) {
        pass_flag = false;
    }
    
    // Fail test if end postision is incorrect
    if (end_x_postion != 37 || end_y_postion != 21) {
        pass_flag = false;
    }

    return pass_flag;
}
#endif