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