Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Weapons/Weapons_test.h

Committer:
evanso
Date:
2020-05-25
Revision:
82:3211b31e9421
Parent:
37:a05eac7fcb4c
Child:
85:87bc28b151d8

File content as of revision 82:3211b31e9421:

#ifndef WEAPONS_TEST_H
#define WEAPONS_TEST_H

/** Weapons Test
 * @brief Checks that the weapons draws
 * @author Benjamin Evans, University of Leeds
 * @date May 2020
 * @return true if test are passed 
 */
bool weapons_draw_test(int expected_pixel_status,bool direction, 
int bullet_movement, int expected_postion_x, int expected_postion_y) {
    // Objects reqired for test 
    Weapons bullet;
    Spaceship spaceship;
    N5110 lcd;
    
    // Initialise objects for tets
    spaceship.init();
    lcd.init();
    bullet.init(spaceship.get_pos(), direction, true); 
    
    printf("draw_bullet = %d,%d : ", expected_postion_x, expected_postion_y);
    
    // Draws bullet in different posisions
    for(int i = 0;i <= bullet_movement; i++) {
        bullet.draw_bullet(lcd);
    }
    
    // Reads pixel where bullet is expected to be drawn 
    int actual_pixel_status = lcd.getPixel(expected_postion_x, 
    expected_postion_y);
    
    // Checks if pixel is drawn and therefor testing it hasnt gone of screen
    if (actual_pixel_status) {
        printf ( "Passed!\n");
        return true;
    } else {
        printf ( "Failed! value = %d  (expecting  %d)\n", actual_pixel_status, 
        expected_pixel_status);
        return false;
    }
}

#endif