Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Sat May 16 17:19:18 2020 +0000
Revision:
38:75bd968daa31
Parent:
37:a05eac7fcb4c
Child:
82:3211b31e9421
Added one more unit test, collision of alien and people, which it passed. This also confirms that collision of alien and spaceship will work as it inherits same parent method.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 37:a05eac7fcb4c 1 #ifndef PEOPLE_TEST_H
evanso 37:a05eac7fcb4c 2 #define PEOPLE_TEST_H
evanso 37:a05eac7fcb4c 3
evanso 37:a05eac7fcb4c 4 /** People Test
evanso 37:a05eac7fcb4c 5 * @brief Checks People draw corectly and moves joystick direction
evanso 37:a05eac7fcb4c 6 * @author Benjamin Evans, University of Leeds
evanso 37:a05eac7fcb4c 7 * @date April 2020
evanso 37:a05eac7fcb4c 8 * @return true if test are passed
evanso 37:a05eac7fcb4c 9 */
evanso 37:a05eac7fcb4c 10 bool people_draw_test(Direction d_, int expected_pixel_status, int expected_x){
evanso 37:a05eac7fcb4c 11 // Objects reqired for test
evanso 37:a05eac7fcb4c 12 Gamepad pad;
evanso 37:a05eac7fcb4c 13 Map map;
evanso 37:a05eac7fcb4c 14 People people;
evanso 37:a05eac7fcb4c 15 N5110 lcd;
evanso 37:a05eac7fcb4c 16
evanso 37:a05eac7fcb4c 17 // Initialises
evanso 37:a05eac7fcb4c 18 pad.init();
evanso 37:a05eac7fcb4c 19 lcd.init();
evanso 37:a05eac7fcb4c 20 map.init(pad);
evanso 37:a05eac7fcb4c 21 people.init(pad,expected_x),
evanso 37:a05eac7fcb4c 22
evanso 37:a05eac7fcb4c 23 printf(" expected pixel status = %d ",expected_pixel_status);
evanso 37:a05eac7fcb4c 24
evanso 37:a05eac7fcb4c 25 // Draws people
evanso 37:a05eac7fcb4c 26 people.draw_people(lcd, d_, map.get_length_map(), map.get_position_x_map());
evanso 37:a05eac7fcb4c 27
evanso 37:a05eac7fcb4c 28 // gets the position of person as it's random
evanso 37:a05eac7fcb4c 29 Vector2D people_pos = people.get_pos();
evanso 37:a05eac7fcb4c 30
evanso 37:a05eac7fcb4c 31 // Reads pixel where person is expected to be drawn
evanso 37:a05eac7fcb4c 32 int actual_pixel_status = lcd.getPixel(people_pos.x + 1,
evanso 37:a05eac7fcb4c 33 people_pos.y + 1);
evanso 37:a05eac7fcb4c 34
evanso 37:a05eac7fcb4c 35 // Checks if pixel is drawn and therefor testing it hasnt gone of screen
evanso 37:a05eac7fcb4c 36 if (actual_pixel_status == expected_pixel_status) {
evanso 37:a05eac7fcb4c 37 printf ( "Passed!\n");
evanso 37:a05eac7fcb4c 38 return true;
evanso 37:a05eac7fcb4c 39 } else {
evanso 37:a05eac7fcb4c 40 printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status,
evanso 37:a05eac7fcb4c 41 expected_pixel_status);
evanso 37:a05eac7fcb4c 42 return false;
evanso 37:a05eac7fcb4c 43 }
evanso 37:a05eac7fcb4c 44 }
evanso 38:75bd968daa31 45
evanso 38:75bd968daa31 46 bool check_alien_collision_test(bool expected_collision, int expected_x){
evanso 38:75bd968daa31 47
evanso 38:75bd968daa31 48 // Objects reqired for test
evanso 38:75bd968daa31 49 Alien alien;
evanso 38:75bd968daa31 50 People people;
evanso 38:75bd968daa31 51 Gamepad pad;
evanso 38:75bd968daa31 52
evanso 38:75bd968daa31 53 // Initialise people x start position
evanso 38:75bd968daa31 54 people.init(pad,expected_x);
evanso 38:75bd968daa31 55
evanso 38:75bd968daa31 56 printf("collision = %s : " ,expected_collision ? "true" : "false");
evanso 38:75bd968daa31 57
evanso 38:75bd968daa31 58 // initialise alien to people posision
evanso 38:75bd968daa31 59 alien.init(pad,expected_x,43);
evanso 38:75bd968daa31 60
evanso 38:75bd968daa31 61 // Checks collision function
evanso 38:75bd968daa31 62 bool actual_collision = people.check_alien_collision(alien);
evanso 38:75bd968daa31 63
evanso 38:75bd968daa31 64 // Checks if collision is espected
evanso 38:75bd968daa31 65 if (actual_collision == expected_collision) {
evanso 38:75bd968daa31 66 printf ( "Passed!\n");
evanso 38:75bd968daa31 67 return true;
evanso 38:75bd968daa31 68 } else {
evanso 38:75bd968daa31 69 printf ("Failed! value = %s (expecting %d)\n",
evanso 38:75bd968daa31 70 actual_collision ? "true" : "false",
evanso 38:75bd968daa31 71 expected_collision ? "true" : "false");
evanso 38:75bd968daa31 72 return false;
evanso 38:75bd968daa31 73 }
evanso 38:75bd968daa31 74 }
evanso 37:a05eac7fcb4c 75 #endif