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:
Thu May 21 17:37:15 2020 +0000
Revision:
66:33f479036a5d
Parent:
65:daa792a09e1f
Child:
67:a2984682d641
Added draw HUD unit test which it passed!

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 22:053c11a202e1 6 #include "Alien_test.h"
evanso 23:cc44e26c08fa 7 #include "Weapons_test.h"
evanso 26:1a7056eb3253 8 #include "Explosion_test.h"
evanso 37:a05eac7fcb4c 9 #include "People_test.h"
evanso 65:daa792a09e1f 10 #include "Menu_test.h"
evanso 66:33f479036a5d 11 #include "HUD_test.h"
evanso 11:ab578a151f67 12
evanso 11:ab578a151f67 13 /** Test
evanso 27:8bb2bd97c319 14 * @brief Runs all tests for game
evanso 27:8bb2bd97c319 15 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 16 * @date April 2020
evanso 27:8bb2bd97c319 17 */
evanso 13:12276eed13ac 18 // Spaceship tests -------------------------------------------------------------
evanso 65:daa792a09e1f 19
evanso 13:12276eed13ac 20 void run_spaceship_movement_tests(){
evanso 13:12276eed13ac 21 printf ("\nTesting spaceship_movement_test() \n");
evanso 13:12276eed13ac 22 int passed_counter = 0;
evanso 13:12276eed13ac 23
evanso 13:12276eed13ac 24 // Runs test with all posible movment directions
evanso 13:12276eed13ac 25 if (spaceship_movement_test(CENTRE, 36, 22)) passed_counter++;
evanso 13:12276eed13ac 26 if (spaceship_movement_test(N, 36, 21)) passed_counter++;
evanso 16:1ee3d3804557 27 if (spaceship_movement_test(NE, 35, 21)) passed_counter++;
evanso 16:1ee3d3804557 28 if (spaceship_movement_test(E, 35, 22)) passed_counter++;
evanso 16:1ee3d3804557 29 if (spaceship_movement_test(SE, 35, 23)) passed_counter++;
evanso 13:12276eed13ac 30 if (spaceship_movement_test(S, 36, 23)) passed_counter++;
evanso 16:1ee3d3804557 31 if (spaceship_movement_test(SW, 37, 23)) passed_counter++;
evanso 16:1ee3d3804557 32 if (spaceship_movement_test(W, 37, 22)) passed_counter++;
evanso 16:1ee3d3804557 33 if (spaceship_movement_test(NW, 37, 21)) passed_counter++;
evanso 11:ab578a151f67 34
evanso 13:12276eed13ac 35 // prints results
evanso 37:a05eac7fcb4c 36 printf ("\nspaceship_movement_test passed %d tests out of 9\n\n\n",
evanso 27:8bb2bd97c319 37 passed_counter);
evanso 12:1c0b6796aaca 38 }
evanso 12:1c0b6796aaca 39
evanso 13:12276eed13ac 40 void run_spaceship_draw_tests(){
evanso 37:a05eac7fcb4c 41 printf ("\nTesting spaceship_draw_tests() \n\n");
evanso 13:12276eed13ac 42 int passed_counter = 0;
evanso 12:1c0b6796aaca 43
evanso 13:12276eed13ac 44 // Runs test with max movement directions
evanso 65:daa792a09e1f 45 if (spaceship_draw_test(NE, 1, 15, 9)) passed_counter++;
evanso 16:1ee3d3804557 46 if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++;
evanso 16:1ee3d3804557 47 if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++;
evanso 65:daa792a09e1f 48 if (spaceship_draw_test(NW, 1, 64, 9)) passed_counter++;
evanso 13:12276eed13ac 49
evanso 13:12276eed13ac 50 // prints results
evanso 37:a05eac7fcb4c 51 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 11:ab578a151f67 52 }
evanso 11:ab578a151f67 53
evanso 65:daa792a09e1f 54
evanso 65:daa792a09e1f 55
evanso 13:12276eed13ac 56 // Map tests -------------------------------------------------------------------
evanso 13:12276eed13ac 57
evanso 14:7419c680656f 58 void run_map_draw_tests(){
evanso 37:a05eac7fcb4c 59 printf ("\nTesting map_draw_tests() \n\n");
evanso 14:7419c680656f 60 int passed_counter = 0;
evanso 14:7419c680656f 61
evanso 14:7419c680656f 62 // Runs multiple map tests
evanso 18:11068b98e261 63 if (map_move_test(CENTRE, -84)) passed_counter++;
evanso 18:11068b98e261 64 if (map_move_test(N, -84)) passed_counter++;
evanso 18:11068b98e261 65 if (map_move_test(NE,-86)) passed_counter++;
evanso 18:11068b98e261 66 if (map_move_test(E, -86)) passed_counter++;
evanso 18:11068b98e261 67 if (map_move_test(SE, -86)) passed_counter++;
evanso 18:11068b98e261 68 if (map_move_test(S, -84)) passed_counter++;
evanso 18:11068b98e261 69 if (map_move_test(SW, -82)) passed_counter++;
evanso 18:11068b98e261 70 if (map_move_test(W, -82)) passed_counter++;
evanso 18:11068b98e261 71 if (map_move_test(NW, -82)) passed_counter++;
evanso 14:7419c680656f 72
evanso 14:7419c680656f 73 // prints results
evanso 37:a05eac7fcb4c 74 printf ("\nmap_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 14:7419c680656f 75 }
evanso 13:12276eed13ac 76
evanso 65:daa792a09e1f 77
evanso 65:daa792a09e1f 78
evanso 22:053c11a202e1 79 // Alien tests -----------------------------------------------------------------
evanso 65:daa792a09e1f 80
evanso 37:a05eac7fcb4c 81 void run_alien_draw_tests(){
evanso 37:a05eac7fcb4c 82 printf ("\nTesting alien_draw_test() \n\n");
evanso 22:053c11a202e1 83 int passed_counter = 0;
evanso 22:053c11a202e1 84
evanso 22:053c11a202e1 85 // Runs test with all posible movment directions
evanso 37:a05eac7fcb4c 86 if (alien_draw_test(1,CENTRE, 1, 1)) passed_counter++;
evanso 37:a05eac7fcb4c 87 if (alien_draw_test(1,N, 43, 20)) passed_counter++;
evanso 37:a05eac7fcb4c 88 if (alien_draw_test(0,NE, -23, 6)) passed_counter++;
evanso 37:a05eac7fcb4c 89 if (alien_draw_test(0,E, 23, -34)) passed_counter++;
evanso 37:a05eac7fcb4c 90 if (alien_draw_test(0,SE, -23, -43)) passed_counter++;
evanso 37:a05eac7fcb4c 91 if (alien_draw_test(0,S, 100, 26)) passed_counter++;
evanso 37:a05eac7fcb4c 92 if (alien_draw_test(0,SE, 40, 100)) passed_counter++;
evanso 37:a05eac7fcb4c 93 if (alien_draw_test(1,E, 70, 5)) passed_counter++;
evanso 37:a05eac7fcb4c 94 if (alien_draw_test(1,NE, 6, 44)) passed_counter++;
evanso 22:053c11a202e1 95
evanso 22:053c11a202e1 96 // prints results
evanso 37:a05eac7fcb4c 97 printf ("\nalien_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 22:053c11a202e1 98 }
evanso 22:053c11a202e1 99
evanso 38:75bd968daa31 100 void run_check_collision_test(){
evanso 37:a05eac7fcb4c 101 printf ("\nTesting alien_collision_test() \n\n");
evanso 22:053c11a202e1 102 int passed_counter = 0;
evanso 22:053c11a202e1 103
evanso 22:053c11a202e1 104 // Runs test with all differnt possible inputs
evanso 38:75bd968daa31 105 if (check_collision_test(1, 1, 10,22)) passed_counter++;
evanso 38:75bd968daa31 106 if (check_collision_test(0, 1, 28,40)) passed_counter++;
evanso 38:75bd968daa31 107 if (check_collision_test(1, 0, 11,22)) passed_counter++;
evanso 38:75bd968daa31 108 if (check_collision_test(0, 0, 20,22)) passed_counter++;
evanso 22:053c11a202e1 109
evanso 22:053c11a202e1 110 // prints results
evanso 37:a05eac7fcb4c 111 printf ("\nalien_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 22:053c11a202e1 112 }
evanso 15:90b6821bcf64 113
evanso 65:daa792a09e1f 114
evanso 27:8bb2bd97c319 115 // Weapons tests ---------------------------------------------------------------
evanso 65:daa792a09e1f 116
evanso 23:cc44e26c08fa 117 void run_weapons_draw_tests(){
evanso 37:a05eac7fcb4c 118 printf ("\nTesting spaceship_draw_tests() \n\n");
evanso 23:cc44e26c08fa 119 int passed_counter = 0;
evanso 23:cc44e26c08fa 120
evanso 23:cc44e26c08fa 121 // Runs test with max movement directions
evanso 23:cc44e26c08fa 122 if (weapons_draw_test(1, 1, 1, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 123 if (weapons_draw_test(1, 1, 2, 52, 24)) passed_counter++;
evanso 23:cc44e26c08fa 124 if (weapons_draw_test(0, 1, 2, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 125 if (weapons_draw_test(1, 0, 1, 36, 24)) passed_counter++;
evanso 23:cc44e26c08fa 126 if (weapons_draw_test(1, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 127 if (weapons_draw_test(0, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 128
evanso 23:cc44e26c08fa 129 // prints results
evanso 37:a05eac7fcb4c 130 printf ("\nspaceship_draw_test passed %d tests out of 6\n\n\n",passed_counter);
evanso 23:cc44e26c08fa 131 }
evanso 26:1a7056eb3253 132
evanso 65:daa792a09e1f 133
evanso 65:daa792a09e1f 134
evanso 27:8bb2bd97c319 135 // Explosion tests -------------------------------------------------------------
evanso 65:daa792a09e1f 136
evanso 26:1a7056eb3253 137 void run_explosion_draw_tests(){
evanso 37:a05eac7fcb4c 138 printf ("\nTesting explosion_draw_tests() \n\n");
evanso 26:1a7056eb3253 139 int passed_counter = 0;
evanso 26:1a7056eb3253 140
evanso 26:1a7056eb3253 141 // Runs test with max movement directions
evanso 26:1a7056eb3253 142 if (explosion_draw_test(1, 15, 3)) passed_counter++;
evanso 26:1a7056eb3253 143 if (explosion_draw_test(1, 15, 44)) passed_counter++;
evanso 26:1a7056eb3253 144 if (explosion_draw_test(1, 64, 44)) passed_counter++;
evanso 26:1a7056eb3253 145 if (explosion_draw_test(1, 64, 2)) passed_counter++;
evanso 26:1a7056eb3253 146
evanso 26:1a7056eb3253 147 // prints results
evanso 37:a05eac7fcb4c 148 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter);
evanso 37:a05eac7fcb4c 149 }
evanso 37:a05eac7fcb4c 150
evanso 65:daa792a09e1f 151
evanso 65:daa792a09e1f 152
evanso 37:a05eac7fcb4c 153 // People tests ----------------------------------------------------------------
evanso 37:a05eac7fcb4c 154
evanso 37:a05eac7fcb4c 155 void run_people_draw_tests(){
evanso 37:a05eac7fcb4c 156 printf ("\nTesting people_draw_tests() \n\n");
evanso 37:a05eac7fcb4c 157 int passed_counter = 0;
evanso 37:a05eac7fcb4c 158
evanso 37:a05eac7fcb4c 159 // Runs test with max movement directions
evanso 37:a05eac7fcb4c 160 if (people_draw_test(CENTRE, 1,44)) passed_counter++;
evanso 37:a05eac7fcb4c 161 if (people_draw_test(N, 0,100)) passed_counter++;
evanso 37:a05eac7fcb4c 162 if (people_draw_test(NE, 0, -100)) passed_counter++;
evanso 37:a05eac7fcb4c 163 if (people_draw_test(E, 1,0)) passed_counter++;
evanso 37:a05eac7fcb4c 164 if (people_draw_test(SE, 1,82)) passed_counter++;
evanso 37:a05eac7fcb4c 165 if (people_draw_test(S, 1,43)) passed_counter++;
evanso 37:a05eac7fcb4c 166 if (people_draw_test(SW, 0,-64)) passed_counter++;
evanso 37:a05eac7fcb4c 167 if (people_draw_test(W, 0,-6)) passed_counter++;
evanso 37:a05eac7fcb4c 168 if (people_draw_test(NW, 0,84)) passed_counter++;
evanso 37:a05eac7fcb4c 169
evanso 37:a05eac7fcb4c 170 // prints results
evanso 37:a05eac7fcb4c 171 printf ("\npeople_draw_test passed %d tests out of 9\n\n\n",passed_counter);
evanso 26:1a7056eb3253 172 }
evanso 27:8bb2bd97c319 173
evanso 38:75bd968daa31 174 void run_check_alien_collision_test(){
evanso 38:75bd968daa31 175 printf ("\nTesting check_alien_collision_test() \n\n");
evanso 38:75bd968daa31 176 int passed_counter = 0;
evanso 38:75bd968daa31 177
evanso 38:75bd968daa31 178 // Runs test with all differnt possible inputs
evanso 38:75bd968daa31 179 if (check_alien_collision_test(1,1)) passed_counter++;
evanso 38:75bd968daa31 180 if (check_alien_collision_test(1,80)) passed_counter++;
evanso 38:75bd968daa31 181 if (check_alien_collision_test(1,-42)) passed_counter++;
evanso 38:75bd968daa31 182 if (check_alien_collision_test(1,100)) passed_counter++;
evanso 38:75bd968daa31 183
evanso 38:75bd968daa31 184 // prints results
evanso 65:daa792a09e1f 185 printf ("\ncheck_alien_collision_test passed %d tests out of 4\n\n\n",
evanso 65:daa792a09e1f 186 passed_counter);
evanso 65:daa792a09e1f 187 }
evanso 65:daa792a09e1f 188
evanso 65:daa792a09e1f 189
evanso 65:daa792a09e1f 190
evanso 65:daa792a09e1f 191 // Menu tests ------------------------------------------------------------------
evanso 65:daa792a09e1f 192
evanso 65:daa792a09e1f 193 void run_menu_select_part_test(){
evanso 65:daa792a09e1f 194 printf ("\nTesting menu_select_part_test() \n\n");
evanso 65:daa792a09e1f 195 int passed_counter = 0;
evanso 65:daa792a09e1f 196
evanso 65:daa792a09e1f 197 // Runs test with all differnt possible inputs
evanso 65:daa792a09e1f 198 if (menu_select_part_test(play,1)) passed_counter++;
evanso 65:daa792a09e1f 199 if (menu_select_part_test(main_menu,0)) passed_counter++;
evanso 65:daa792a09e1f 200
evanso 65:daa792a09e1f 201 // prints results
evanso 65:daa792a09e1f 202 printf ("\nmenu_select_part_test passed %d tests out of 2\n\n\n",
evanso 65:daa792a09e1f 203 passed_counter);
evanso 65:daa792a09e1f 204 }
evanso 65:daa792a09e1f 205
evanso 65:daa792a09e1f 206 void run_menu_scroll_test(){
evanso 65:daa792a09e1f 207 printf ("\nTesting menu_scroll_test() \n\n");
evanso 65:daa792a09e1f 208 int passed_counter = 0;
evanso 65:daa792a09e1f 209
evanso 65:daa792a09e1f 210 // Runs test with all differnt possible inputs
evanso 65:daa792a09e1f 211 if (menu_scroll_test(CENTRE, play)) passed_counter++;
evanso 65:daa792a09e1f 212 if (menu_scroll_test(N, settings)) passed_counter++;
evanso 65:daa792a09e1f 213 if (menu_scroll_test(NE, settings)) passed_counter++;
evanso 65:daa792a09e1f 214 if (menu_scroll_test(E, play)) passed_counter++;
evanso 65:daa792a09e1f 215 if (menu_scroll_test(SE, saved_games)) passed_counter++;
evanso 65:daa792a09e1f 216 if (menu_scroll_test(S, saved_games)) passed_counter++;
evanso 65:daa792a09e1f 217 if (menu_scroll_test(SW, saved_games)) passed_counter++;
evanso 65:daa792a09e1f 218 if (menu_scroll_test(W, play)) passed_counter++;
evanso 65:daa792a09e1f 219 if (menu_scroll_test(NW, settings)) passed_counter++;
evanso 65:daa792a09e1f 220
evanso 65:daa792a09e1f 221 // prints results
evanso 65:daa792a09e1f 222 printf ("\nmenu_scroll_test passed %d tests out of 9\n\n\n",
evanso 65:daa792a09e1f 223 passed_counter);
evanso 38:75bd968daa31 224 }
evanso 38:75bd968daa31 225
evanso 66:33f479036a5d 226
evanso 66:33f479036a5d 227
evanso 66:33f479036a5d 228 // HUD tests -------------------------------------------------------------------
evanso 66:33f479036a5d 229
evanso 66:33f479036a5d 230 void run_HUD_draw_test(){
evanso 66:33f479036a5d 231 printf ("\nTesting HUD_draw_test() \n\n");
evanso 66:33f479036a5d 232 int passed_counter = 0;
evanso 66:33f479036a5d 233
evanso 66:33f479036a5d 234 // Runs test with all differnt possible inputs
evanso 66:33f479036a5d 235 if (HUD_draw_test(3, 0, 4, 1, 3, 3)) passed_counter++;
evanso 66:33f479036a5d 236 if (HUD_draw_test(3, 0, 4, 1, 12, 3)) passed_counter++;
evanso 66:33f479036a5d 237 if (HUD_draw_test(1, 0, 4, 0, 12, 3)) passed_counter++;
evanso 66:33f479036a5d 238 if (HUD_draw_test(3, 0, 4, 1, 62, 3)) passed_counter++;
evanso 66:33f479036a5d 239 if (HUD_draw_test(3, 0, 3, 0, 62, 3)) passed_counter++;
evanso 66:33f479036a5d 240 if (HUD_draw_test(3, 0, 3, 1, 30, 3)) passed_counter++;
evanso 66:33f479036a5d 241 if (HUD_draw_test(3, 1111, 3, 00, 30, 3)) passed_counter++;
evanso 66:33f479036a5d 242
evanso 66:33f479036a5d 243 // prints results
evanso 66:33f479036a5d 244 printf ("\nHUD_draw_test passed %d tests out of 7\n\n\n",
evanso 66:33f479036a5d 245 passed_counter);
evanso 66:33f479036a5d 246 }
evanso 66:33f479036a5d 247
evanso 11:ab578a151f67 248 #endif