Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

Committer:
evanso
Date:
Sat May 16 17:19:18 2020 +0000
Revision:
38:75bd968daa31
Parent:
37:a05eac7fcb4c
Child:
65:daa792a09e1f
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 11:ab578a151f67 1 #ifndef TESTS_H
evanso 11:ab578a151f67 2 #define TESTS_H
evanso 11:ab578a151f67 3
evanso 11:ab578a151f67 4 #include "Spaceship_test.h"
evanso 14:7419c680656f 5 #include "Map_test.h"
evanso 15:90b6821bcf64 6 #include "GameEngine_test.h"
evanso 22:053c11a202e1 7 #include "Alien_test.h"
evanso 23:cc44e26c08fa 8 #include "Weapons_test.h"
evanso 26:1a7056eb3253 9 #include "Explosion_test.h"
evanso 37:a05eac7fcb4c 10 #include "People_test.h"
evanso 11:ab578a151f67 11
evanso 11:ab578a151f67 12 /** Test
evanso 27:8bb2bd97c319 13 * @brief Runs all tests for game
evanso 27:8bb2bd97c319 14 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 15 * @date April 2020
evanso 27:8bb2bd97c319 16 */
evanso 13:12276eed13ac 17 // Spaceship tests -------------------------------------------------------------
evanso 13:12276eed13ac 18 void run_spaceship_movement_tests(){
evanso 13:12276eed13ac 19 printf ("\nTesting spaceship_movement_test() \n");
evanso 13:12276eed13ac 20 int passed_counter = 0;
evanso 13:12276eed13ac 21
evanso 13:12276eed13ac 22 // Runs test with all posible movment directions
evanso 13:12276eed13ac 23 if (spaceship_movement_test(CENTRE, 36, 22)) passed_counter++;
evanso 13:12276eed13ac 24 if (spaceship_movement_test(N, 36, 21)) passed_counter++;
evanso 16:1ee3d3804557 25 if (spaceship_movement_test(NE, 35, 21)) passed_counter++;
evanso 16:1ee3d3804557 26 if (spaceship_movement_test(E, 35, 22)) passed_counter++;
evanso 16:1ee3d3804557 27 if (spaceship_movement_test(SE, 35, 23)) passed_counter++;
evanso 13:12276eed13ac 28 if (spaceship_movement_test(S, 36, 23)) passed_counter++;
evanso 16:1ee3d3804557 29 if (spaceship_movement_test(SW, 37, 23)) passed_counter++;
evanso 16:1ee3d3804557 30 if (spaceship_movement_test(W, 37, 22)) passed_counter++;
evanso 16:1ee3d3804557 31 if (spaceship_movement_test(NW, 37, 21)) passed_counter++;
evanso 11:ab578a151f67 32
evanso 13:12276eed13ac 33 // prints results
evanso 37:a05eac7fcb4c 34 printf ("\nspaceship_movement_test passed %d tests out of 9\n\n\n",
evanso 27:8bb2bd97c319 35 passed_counter);
evanso 12:1c0b6796aaca 36 }
evanso 12:1c0b6796aaca 37
evanso 13:12276eed13ac 38 void run_spaceship_draw_tests(){
evanso 37:a05eac7fcb4c 39 printf ("\nTesting spaceship_draw_tests() \n\n");
evanso 13:12276eed13ac 40 int passed_counter = 0;
evanso 12:1c0b6796aaca 41
evanso 13:12276eed13ac 42 // Runs test with max movement directions
evanso 16:1ee3d3804557 43 if (spaceship_draw_test(NE, 1, 15, 0)) passed_counter++;
evanso 16:1ee3d3804557 44 if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++;
evanso 16:1ee3d3804557 45 if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++;
evanso 16:1ee3d3804557 46 if (spaceship_draw_test(NW, 1, 64, 0)) passed_counter++;
evanso 13:12276eed13ac 47
evanso 13:12276eed13ac 48 // prints results
evanso 37:a05eac7fcb4c 49 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 11:ab578a151f67 50 }
evanso 11:ab578a151f67 51
evanso 13:12276eed13ac 52 // Map tests -------------------------------------------------------------------
evanso 13:12276eed13ac 53
evanso 14:7419c680656f 54 void run_map_draw_tests(){
evanso 37:a05eac7fcb4c 55 printf ("\nTesting map_draw_tests() \n\n");
evanso 14:7419c680656f 56 int passed_counter = 0;
evanso 14:7419c680656f 57
evanso 14:7419c680656f 58 // Runs multiple map tests
evanso 18:11068b98e261 59 if (map_move_test(CENTRE, -84)) passed_counter++;
evanso 18:11068b98e261 60 if (map_move_test(N, -84)) passed_counter++;
evanso 18:11068b98e261 61 if (map_move_test(NE,-86)) passed_counter++;
evanso 18:11068b98e261 62 if (map_move_test(E, -86)) passed_counter++;
evanso 18:11068b98e261 63 if (map_move_test(SE, -86)) passed_counter++;
evanso 18:11068b98e261 64 if (map_move_test(S, -84)) passed_counter++;
evanso 18:11068b98e261 65 if (map_move_test(SW, -82)) passed_counter++;
evanso 18:11068b98e261 66 if (map_move_test(W, -82)) passed_counter++;
evanso 18:11068b98e261 67 if (map_move_test(NW, -82)) passed_counter++;
evanso 14:7419c680656f 68
evanso 14:7419c680656f 69 // prints results
evanso 37:a05eac7fcb4c 70 printf ("\nmap_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 14:7419c680656f 71 }
evanso 13:12276eed13ac 72
evanso 22:053c11a202e1 73 // Alien tests -----------------------------------------------------------------
evanso 37:a05eac7fcb4c 74 void run_alien_draw_tests(){
evanso 37:a05eac7fcb4c 75 printf ("\nTesting alien_draw_test() \n\n");
evanso 22:053c11a202e1 76 int passed_counter = 0;
evanso 22:053c11a202e1 77
evanso 22:053c11a202e1 78 // Runs test with all posible movment directions
evanso 37:a05eac7fcb4c 79 if (alien_draw_test(1,CENTRE, 1, 1)) passed_counter++;
evanso 37:a05eac7fcb4c 80 if (alien_draw_test(1,N, 43, 20)) passed_counter++;
evanso 37:a05eac7fcb4c 81 if (alien_draw_test(0,NE, -23, 6)) passed_counter++;
evanso 37:a05eac7fcb4c 82 if (alien_draw_test(0,E, 23, -34)) passed_counter++;
evanso 37:a05eac7fcb4c 83 if (alien_draw_test(0,SE, -23, -43)) passed_counter++;
evanso 37:a05eac7fcb4c 84 if (alien_draw_test(0,S, 100, 26)) passed_counter++;
evanso 37:a05eac7fcb4c 85 if (alien_draw_test(0,SE, 40, 100)) passed_counter++;
evanso 37:a05eac7fcb4c 86 if (alien_draw_test(1,E, 70, 5)) passed_counter++;
evanso 37:a05eac7fcb4c 87 if (alien_draw_test(1,NE, 6, 44)) passed_counter++;
evanso 22:053c11a202e1 88
evanso 22:053c11a202e1 89 // prints results
evanso 37:a05eac7fcb4c 90 printf ("\nalien_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 22:053c11a202e1 91 }
evanso 22:053c11a202e1 92
evanso 38:75bd968daa31 93 void run_check_collision_test(){
evanso 37:a05eac7fcb4c 94 printf ("\nTesting alien_collision_test() \n\n");
evanso 22:053c11a202e1 95 int passed_counter = 0;
evanso 22:053c11a202e1 96
evanso 22:053c11a202e1 97 // Runs test with all differnt possible inputs
evanso 38:75bd968daa31 98 if (check_collision_test(1, 1, 10,22)) passed_counter++;
evanso 38:75bd968daa31 99 if (check_collision_test(0, 1, 28,40)) passed_counter++;
evanso 38:75bd968daa31 100 if (check_collision_test(1, 0, 11,22)) passed_counter++;
evanso 38:75bd968daa31 101 if (check_collision_test(0, 0, 20,22)) passed_counter++;
evanso 22:053c11a202e1 102
evanso 22:053c11a202e1 103 // prints results
evanso 37:a05eac7fcb4c 104 printf ("\nalien_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 22:053c11a202e1 105 }
evanso 15:90b6821bcf64 106
evanso 27:8bb2bd97c319 107 // Weapons tests ---------------------------------------------------------------
evanso 23:cc44e26c08fa 108 void run_weapons_draw_tests(){
evanso 37:a05eac7fcb4c 109 printf ("\nTesting spaceship_draw_tests() \n\n");
evanso 23:cc44e26c08fa 110 int passed_counter = 0;
evanso 23:cc44e26c08fa 111
evanso 23:cc44e26c08fa 112 // Runs test with max movement directions
evanso 23:cc44e26c08fa 113 if (weapons_draw_test(1, 1, 1, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 114 if (weapons_draw_test(1, 1, 2, 52, 24)) passed_counter++;
evanso 23:cc44e26c08fa 115 if (weapons_draw_test(0, 1, 2, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 116 if (weapons_draw_test(1, 0, 1, 36, 24)) passed_counter++;
evanso 23:cc44e26c08fa 117 if (weapons_draw_test(1, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 118 if (weapons_draw_test(0, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 119
evanso 23:cc44e26c08fa 120 // prints results
evanso 37:a05eac7fcb4c 121 printf ("\nspaceship_draw_test passed %d tests out of 6\n\n\n",passed_counter);
evanso 23:cc44e26c08fa 122 }
evanso 26:1a7056eb3253 123
evanso 27:8bb2bd97c319 124 // Explosion tests -------------------------------------------------------------
evanso 26:1a7056eb3253 125 void run_explosion_draw_tests(){
evanso 37:a05eac7fcb4c 126 printf ("\nTesting explosion_draw_tests() \n\n");
evanso 26:1a7056eb3253 127 int passed_counter = 0;
evanso 26:1a7056eb3253 128
evanso 26:1a7056eb3253 129 // Runs test with max movement directions
evanso 26:1a7056eb3253 130 if (explosion_draw_test(1, 15, 3)) passed_counter++;
evanso 26:1a7056eb3253 131 if (explosion_draw_test(1, 15, 44)) passed_counter++;
evanso 26:1a7056eb3253 132 if (explosion_draw_test(1, 64, 44)) passed_counter++;
evanso 26:1a7056eb3253 133 if (explosion_draw_test(1, 64, 2)) passed_counter++;
evanso 26:1a7056eb3253 134
evanso 26:1a7056eb3253 135 // prints results
evanso 37:a05eac7fcb4c 136 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 37:a05eac7fcb4c 137 }
evanso 37:a05eac7fcb4c 138
evanso 37:a05eac7fcb4c 139 // People tests ----------------------------------------------------------------
evanso 37:a05eac7fcb4c 140
evanso 37:a05eac7fcb4c 141 void run_people_draw_tests(){
evanso 37:a05eac7fcb4c 142 printf ("\nTesting people_draw_tests() \n\n");
evanso 37:a05eac7fcb4c 143 int passed_counter = 0;
evanso 37:a05eac7fcb4c 144
evanso 37:a05eac7fcb4c 145 // Runs test with max movement directions
evanso 37:a05eac7fcb4c 146 if (people_draw_test(CENTRE, 1,44)) passed_counter++;
evanso 37:a05eac7fcb4c 147 if (people_draw_test(N, 0,100)) passed_counter++;
evanso 37:a05eac7fcb4c 148 if (people_draw_test(NE, 0, -100)) passed_counter++;
evanso 37:a05eac7fcb4c 149 if (people_draw_test(E, 1,0)) passed_counter++;
evanso 37:a05eac7fcb4c 150 if (people_draw_test(SE, 1,82)) passed_counter++;
evanso 37:a05eac7fcb4c 151 if (people_draw_test(S, 1,43)) passed_counter++;
evanso 37:a05eac7fcb4c 152 if (people_draw_test(SW, 0,-64)) passed_counter++;
evanso 37:a05eac7fcb4c 153 if (people_draw_test(W, 0,-6)) passed_counter++;
evanso 37:a05eac7fcb4c 154 if (people_draw_test(NW, 0,84)) passed_counter++;
evanso 37:a05eac7fcb4c 155
evanso 37:a05eac7fcb4c 156 // prints results
evanso 37:a05eac7fcb4c 157 printf ("\npeople_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 26:1a7056eb3253 158 }
evanso 27:8bb2bd97c319 159
evanso 38:75bd968daa31 160 void run_check_alien_collision_test(){
evanso 38:75bd968daa31 161 printf ("\nTesting check_alien_collision_test() \n\n");
evanso 38:75bd968daa31 162 int passed_counter = 0;
evanso 38:75bd968daa31 163
evanso 38:75bd968daa31 164 // Runs test with all differnt possible inputs
evanso 38:75bd968daa31 165 if (check_alien_collision_test(1,1)) passed_counter++;
evanso 38:75bd968daa31 166 if (check_alien_collision_test(1,80)) passed_counter++;
evanso 38:75bd968daa31 167 if (check_alien_collision_test(1,-42)) passed_counter++;
evanso 38:75bd968daa31 168 if (check_alien_collision_test(1,100)) passed_counter++;
evanso 38:75bd968daa31 169
evanso 38:75bd968daa31 170 // prints results
evanso 38:75bd968daa31 171 printf ("\ncheck_alien_collision_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 38:75bd968daa31 172 }
evanso 38:75bd968daa31 173
evanso 11:ab578a151f67 174 #endif