Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Mon May 25 18:39:51 2020 +0000
Revision:
82:3211b31e9421
Parent:
37:a05eac7fcb4c
Child:
85:87bc28b151d8
Made commenting and formatting of code more consistent.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 23:cc44e26c08fa 1 #ifndef WEAPONS_TEST_H
evanso 23:cc44e26c08fa 2 #define WEAPONS_TEST_H
evanso 23:cc44e26c08fa 3
evanso 23:cc44e26c08fa 4 /** Weapons Test
evanso 27:8bb2bd97c319 5 * @brief Checks that the weapons draws
evanso 27:8bb2bd97c319 6 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 7 * @date May 2020
evanso 27:8bb2bd97c319 8 * @return true if test are passed
evanso 27:8bb2bd97c319 9 */
evanso 27:8bb2bd97c319 10 bool weapons_draw_test(int expected_pixel_status,bool direction,
evanso 82:3211b31e9421 11 int bullet_movement, int expected_postion_x, int expected_postion_y) {
evanso 23:cc44e26c08fa 12 // Objects reqired for test
evanso 23:cc44e26c08fa 13 Weapons bullet;
evanso 23:cc44e26c08fa 14 Spaceship spaceship;
evanso 23:cc44e26c08fa 15 N5110 lcd;
evanso 23:cc44e26c08fa 16
evanso 23:cc44e26c08fa 17 // Initialise objects for tets
evanso 23:cc44e26c08fa 18 spaceship.init();
evanso 23:cc44e26c08fa 19 lcd.init();
evanso 37:a05eac7fcb4c 20 bullet.init(spaceship.get_pos(), direction, true);
evanso 23:cc44e26c08fa 21
evanso 23:cc44e26c08fa 22 printf("draw_bullet = %d,%d : ", expected_postion_x, expected_postion_y);
evanso 23:cc44e26c08fa 23
evanso 82:3211b31e9421 24 // Draws bullet in different posisions
evanso 82:3211b31e9421 25 for(int i = 0;i <= bullet_movement; i++) {
evanso 23:cc44e26c08fa 26 bullet.draw_bullet(lcd);
evanso 23:cc44e26c08fa 27 }
evanso 23:cc44e26c08fa 28
evanso 23:cc44e26c08fa 29 // Reads pixel where bullet is expected to be drawn
evanso 27:8bb2bd97c319 30 int actual_pixel_status = lcd.getPixel(expected_postion_x,
evanso 27:8bb2bd97c319 31 expected_postion_y);
evanso 23:cc44e26c08fa 32
evanso 23:cc44e26c08fa 33 // Checks if pixel is drawn and therefor testing it hasnt gone of screen
evanso 23:cc44e26c08fa 34 if (actual_pixel_status) {
evanso 23:cc44e26c08fa 35 printf ( "Passed!\n");
evanso 23:cc44e26c08fa 36 return true;
evanso 23:cc44e26c08fa 37 } else {
evanso 27:8bb2bd97c319 38 printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status,
evanso 27:8bb2bd97c319 39 expected_pixel_status);
evanso 23:cc44e26c08fa 40 return false;
evanso 23:cc44e26c08fa 41 }
evanso 23:cc44e26c08fa 42 }
evanso 23:cc44e26c08fa 43
evanso 23:cc44e26c08fa 44 #endif