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:
Wed May 13 12:02:51 2020 +0000
Revision:
26:1a7056eb3253
Parent:
23:cc44e26c08fa
Child:
27:8bb2bd97c319
Added unit test for explosion class 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 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 11:ab578a151f67 10
evanso 11:ab578a151f67 11 /** Test
evanso 11:ab578a151f67 12 @brief Runs all tests for game
evanso 11:ab578a151f67 13 @author Benjamin Evans, University of Leeds
evanso 13:12276eed13ac 14 @date April 2020
evanso 11:ab578a151f67 15 */
evanso 13:12276eed13ac 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 13:12276eed13ac 34 printf ("\nspaceship_movement_test passed %d tests out of 9\n",passed_counter);
evanso 12:1c0b6796aaca 35 }
evanso 12:1c0b6796aaca 36
evanso 13:12276eed13ac 37 void run_spaceship_draw_tests(){
evanso 13:12276eed13ac 38 printf ("\nTesting spaceship_draw_tests() \n");
evanso 13:12276eed13ac 39 int passed_counter = 0;
evanso 12:1c0b6796aaca 40
evanso 13:12276eed13ac 41 // Runs test with max movement directions
evanso 16:1ee3d3804557 42 if (spaceship_draw_test(NE, 1, 15, 0)) passed_counter++;
evanso 16:1ee3d3804557 43 if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++;
evanso 16:1ee3d3804557 44 if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++;
evanso 16:1ee3d3804557 45 if (spaceship_draw_test(NW, 1, 64, 0)) passed_counter++;
evanso 13:12276eed13ac 46
evanso 13:12276eed13ac 47 // prints results
evanso 13:12276eed13ac 48 printf ("\nspaceship_draw_test passed %d tests out of 4\n",passed_counter);
evanso 11:ab578a151f67 49 }
evanso 11:ab578a151f67 50
evanso 13:12276eed13ac 51 // Map tests -------------------------------------------------------------------
evanso 13:12276eed13ac 52
evanso 14:7419c680656f 53 void run_map_draw_tests(){
evanso 14:7419c680656f 54 printf ("\nTesting map_draw_tests() \n");
evanso 14:7419c680656f 55 int passed_counter = 0;
evanso 14:7419c680656f 56
evanso 14:7419c680656f 57 // Runs multiple map tests
evanso 18:11068b98e261 58 if (map_move_test(CENTRE, -84)) passed_counter++;
evanso 18:11068b98e261 59 if (map_move_test(N, -84)) passed_counter++;
evanso 18:11068b98e261 60 if (map_move_test(NE,-86)) passed_counter++;
evanso 18:11068b98e261 61 if (map_move_test(E, -86)) passed_counter++;
evanso 18:11068b98e261 62 if (map_move_test(SE, -86)) passed_counter++;
evanso 18:11068b98e261 63 if (map_move_test(S, -84)) passed_counter++;
evanso 18:11068b98e261 64 if (map_move_test(SW, -82)) passed_counter++;
evanso 18:11068b98e261 65 if (map_move_test(W, -82)) passed_counter++;
evanso 18:11068b98e261 66 if (map_move_test(NW, -82)) passed_counter++;
evanso 14:7419c680656f 67
evanso 14:7419c680656f 68 // prints results
evanso 18:11068b98e261 69 printf ("\nmap_draw_test passed %d tests out of 9\n",passed_counter);
evanso 14:7419c680656f 70 }
evanso 13:12276eed13ac 71
evanso 22:053c11a202e1 72 // Alien tests -----------------------------------------------------------------
evanso 22:053c11a202e1 73 void run_alien_movement_tests(){
evanso 22:053c11a202e1 74 printf ("\nTesting alien_movement_test() \n");
evanso 22:053c11a202e1 75 int passed_counter = 0;
evanso 22:053c11a202e1 76
evanso 22:053c11a202e1 77 // Runs test with all posible movment directions
evanso 26:1a7056eb3253 78 if (alien_movement_test(0, 1, 0)) passed_counter++;
evanso 26:1a7056eb3253 79 if (alien_movement_test(1, 1, 1)) passed_counter++;
evanso 26:1a7056eb3253 80 if (alien_movement_test(2, 1, -1)) passed_counter++;
evanso 26:1a7056eb3253 81 if (alien_movement_test(3, -1, 0)) passed_counter++;
evanso 26:1a7056eb3253 82 if (alien_movement_test(4, -1, 1)) passed_counter++;
evanso 26:1a7056eb3253 83 if (alien_movement_test(5, -1, -1)) passed_counter++;
evanso 22:053c11a202e1 84
evanso 22:053c11a202e1 85 // prints results
evanso 26:1a7056eb3253 86 printf ("\nalien_movement_test passed %d tests out of 6\n",passed_counter);
evanso 22:053c11a202e1 87 }
evanso 22:053c11a202e1 88
evanso 22:053c11a202e1 89 void run_alien_collision_test(){
evanso 22:053c11a202e1 90 printf ("\nTesting alien_collision_test() \n");
evanso 22:053c11a202e1 91 int passed_counter = 0;
evanso 22:053c11a202e1 92
evanso 22:053c11a202e1 93 // Runs test with all differnt possible inputs
evanso 22:053c11a202e1 94 if (alien_collision_test(1, 1, 10,22)) passed_counter++;
evanso 26:1a7056eb3253 95 if (alien_collision_test(0, 1, 28,40)) passed_counter++;
evanso 22:053c11a202e1 96 if (alien_collision_test(1, 0, 11,22)) passed_counter++;
evanso 22:053c11a202e1 97 if (alien_collision_test(0, 0, 20,22)) passed_counter++;
evanso 22:053c11a202e1 98
evanso 22:053c11a202e1 99 // prints results
evanso 22:053c11a202e1 100 printf ("\nalien_movement_test passed %d tests out of 4\n",passed_counter);
evanso 22:053c11a202e1 101 }
evanso 15:90b6821bcf64 102
evanso 23:cc44e26c08fa 103 // Weapons tests -----------------------------------------------------------------
evanso 23:cc44e26c08fa 104 void run_weapons_draw_tests(){
evanso 23:cc44e26c08fa 105 printf ("\nTesting spaceship_draw_tests() \n");
evanso 23:cc44e26c08fa 106 int passed_counter = 0;
evanso 23:cc44e26c08fa 107
evanso 23:cc44e26c08fa 108 // Runs test with max movement directions
evanso 23:cc44e26c08fa 109 if (weapons_draw_test(1, 1, 1, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 110 if (weapons_draw_test(1, 1, 2, 52, 24)) passed_counter++;
evanso 23:cc44e26c08fa 111 if (weapons_draw_test(0, 1, 2, 49, 24)) passed_counter++;
evanso 23:cc44e26c08fa 112 if (weapons_draw_test(1, 0, 1, 36, 24)) passed_counter++;
evanso 23:cc44e26c08fa 113 if (weapons_draw_test(1, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 114 if (weapons_draw_test(0, 0, 2, 33, 24)) passed_counter++;
evanso 23:cc44e26c08fa 115
evanso 23:cc44e26c08fa 116 // prints results
evanso 23:cc44e26c08fa 117 printf ("\nspaceship_draw_test passed %d tests out of 6\n",passed_counter);
evanso 23:cc44e26c08fa 118 }
evanso 26:1a7056eb3253 119
evanso 26:1a7056eb3253 120 // Explosion tests -----------------------------------------------------------------
evanso 26:1a7056eb3253 121 void run_explosion_draw_tests(){
evanso 26:1a7056eb3253 122 printf ("\nTesting explosion_draw_tests() \n");
evanso 26:1a7056eb3253 123 int passed_counter = 0;
evanso 26:1a7056eb3253 124
evanso 26:1a7056eb3253 125 // Runs test with max movement directions
evanso 26:1a7056eb3253 126 if (explosion_draw_test(1, 15, 3)) passed_counter++;
evanso 26:1a7056eb3253 127 if (explosion_draw_test(1, 15, 44)) passed_counter++;
evanso 26:1a7056eb3253 128 if (explosion_draw_test(1, 64, 44)) passed_counter++;
evanso 26:1a7056eb3253 129 if (explosion_draw_test(1, 64, 2)) passed_counter++;
evanso 26:1a7056eb3253 130
evanso 26:1a7056eb3253 131 // prints results
evanso 26:1a7056eb3253 132 printf ("\nspaceship_draw_test passed %d tests out of 4\n",passed_counter);
evanso 26:1a7056eb3253 133 }
evanso 11:ab578a151f67 134 #endif