Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers People_test.h Source File

People_test.h

00001 #ifndef PEOPLE_TEST_H
00002 #define PEOPLE_TEST_H
00003 
00004 /** People Test
00005  * @brief Checks People draw corectly and moves joystick direction
00006  * @author Benjamin Evans, University of Leeds
00007  * @date April 2020
00008  * @return true if test are passed 
00009  */
00010 bool people_draw_test(Direction d_, int expected_pixel_status, int expected_x){
00011     // Objects required for test 
00012     Gamepad pad;
00013     Map map;
00014     People people;
00015     N5110 lcd;
00016     
00017     // Initialises
00018     pad.init();
00019     lcd.init();
00020     map.init(pad); 
00021     people.init(pad,expected_x),
00022 
00023     printf(" expected pixel status = %d  ",expected_pixel_status);
00024     
00025     // Draws people
00026     people.draw_people(lcd, d_, map.get_length_map(), map.get_position_x_map());
00027     
00028     // Gets the position of person as it's random
00029     Vector2D people_pos = people.get_pos();
00030     
00031     // Reads pixel where person is expected to be drawn 
00032     int actual_pixel_status = lcd.getPixel(people_pos.x + 1, 
00033     people_pos.y + 1);
00034     
00035     // Checks if pixel is drawn and therefor testing it hasn’t gone of screen
00036     if (actual_pixel_status ==  expected_pixel_status) {
00037         printf ( "Passed!\n");
00038         return true;
00039     } else {
00040         printf ( "Failed! value = %d  (expecting  %d)\n", actual_pixel_status, 
00041         expected_pixel_status);
00042         return false;
00043     }
00044 }
00045 
00046 bool check_alien_collision_test(bool expected_collision, int expected_x){
00047     
00048     // Objects required for test 
00049     Alien alien;
00050     People people;
00051     Gamepad pad;
00052     
00053     // Initialise people x start position
00054     people.init(pad,expected_x); 
00055     
00056     printf("collision =  %s : " ,expected_collision ? "true" : "false");
00057     
00058     // Initialise alien to people position
00059     alien.init(pad,expected_x,43);
00060     
00061     // Checks collision function
00062     bool actual_collision = people.check_alien_collision(alien);
00063     
00064     // Checks if collision is expected 
00065     if (actual_collision == expected_collision) {
00066         printf ( "Passed!\n");
00067         return true;
00068     } else {
00069         printf ("Failed! value = %s (expecting  %d)\n", 
00070         actual_collision ? "true" : "false", 
00071         expected_collision ? "true" : "false");
00072         return false;
00073     } 
00074 }
00075 #endif