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 20:23:24 2020 +0000
Revision:
67:a2984682d641
Parent:
66:33f479036a5d
Child:
70:8c4572d17441
Added SaveGame unit test which all passed! Had to define the unit test that tests actually saving and reading from a file as kept getting an error when declaring the sd object.

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