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 06 11:24:22 2020 +0000
Revision:
22:053c11a202e1
Parent:
18:11068b98e261
Child:
23:cc44e26c08fa
Now that the main code structure is finished for alien and weapons I can unit test those classes. Added a unit test for the alien class and 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 11:ab578a151f67 8
evanso 11:ab578a151f67 9 /** Test
evanso 11:ab578a151f67 10 @brief Runs all tests for game
evanso 11:ab578a151f67 11 @author Benjamin Evans, University of Leeds
evanso 13:12276eed13ac 12 @date April 2020
evanso 11:ab578a151f67 13 */
evanso 13:12276eed13ac 14
evanso 13:12276eed13ac 15 // Spaceship tests -------------------------------------------------------------
evanso 13:12276eed13ac 16 void run_spaceship_movement_tests(){
evanso 13:12276eed13ac 17 printf ("\nTesting spaceship_movement_test() \n");
evanso 13:12276eed13ac 18 int passed_counter = 0;
evanso 13:12276eed13ac 19
evanso 13:12276eed13ac 20 // Runs test with all posible movment directions
evanso 13:12276eed13ac 21 if (spaceship_movement_test(CENTRE, 36, 22)) passed_counter++;
evanso 13:12276eed13ac 22 if (spaceship_movement_test(N, 36, 21)) passed_counter++;
evanso 16:1ee3d3804557 23 if (spaceship_movement_test(NE, 35, 21)) passed_counter++;
evanso 16:1ee3d3804557 24 if (spaceship_movement_test(E, 35, 22)) passed_counter++;
evanso 16:1ee3d3804557 25 if (spaceship_movement_test(SE, 35, 23)) passed_counter++;
evanso 13:12276eed13ac 26 if (spaceship_movement_test(S, 36, 23)) passed_counter++;
evanso 16:1ee3d3804557 27 if (spaceship_movement_test(SW, 37, 23)) passed_counter++;
evanso 16:1ee3d3804557 28 if (spaceship_movement_test(W, 37, 22)) passed_counter++;
evanso 16:1ee3d3804557 29 if (spaceship_movement_test(NW, 37, 21)) passed_counter++;
evanso 11:ab578a151f67 30
evanso 13:12276eed13ac 31 // prints results
evanso 13:12276eed13ac 32 printf ("\nspaceship_movement_test passed %d tests out of 9\n",passed_counter);
evanso 12:1c0b6796aaca 33 }
evanso 12:1c0b6796aaca 34
evanso 13:12276eed13ac 35 void run_spaceship_draw_tests(){
evanso 13:12276eed13ac 36 printf ("\nTesting spaceship_draw_tests() \n");
evanso 13:12276eed13ac 37 int passed_counter = 0;
evanso 12:1c0b6796aaca 38
evanso 13:12276eed13ac 39 // Runs test with max movement directions
evanso 16:1ee3d3804557 40 if (spaceship_draw_test(NE, 1, 15, 0)) passed_counter++;
evanso 16:1ee3d3804557 41 if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++;
evanso 16:1ee3d3804557 42 if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++;
evanso 16:1ee3d3804557 43 if (spaceship_draw_test(NW, 1, 64, 0)) passed_counter++;
evanso 13:12276eed13ac 44
evanso 13:12276eed13ac 45 // prints results
evanso 13:12276eed13ac 46 printf ("\nspaceship_draw_test passed %d tests out of 4\n",passed_counter);
evanso 11:ab578a151f67 47 }
evanso 11:ab578a151f67 48
evanso 13:12276eed13ac 49 // Map tests -------------------------------------------------------------------
evanso 13:12276eed13ac 50
evanso 14:7419c680656f 51 void run_map_draw_tests(){
evanso 14:7419c680656f 52 printf ("\nTesting map_draw_tests() \n");
evanso 14:7419c680656f 53 int passed_counter = 0;
evanso 14:7419c680656f 54
evanso 14:7419c680656f 55 // Runs multiple map tests
evanso 18:11068b98e261 56 if (map_move_test(CENTRE, -84)) passed_counter++;
evanso 18:11068b98e261 57 if (map_move_test(N, -84)) passed_counter++;
evanso 18:11068b98e261 58 if (map_move_test(NE,-86)) passed_counter++;
evanso 18:11068b98e261 59 if (map_move_test(E, -86)) passed_counter++;
evanso 18:11068b98e261 60 if (map_move_test(SE, -86)) passed_counter++;
evanso 18:11068b98e261 61 if (map_move_test(S, -84)) passed_counter++;
evanso 18:11068b98e261 62 if (map_move_test(SW, -82)) passed_counter++;
evanso 18:11068b98e261 63 if (map_move_test(W, -82)) passed_counter++;
evanso 18:11068b98e261 64 if (map_move_test(NW, -82)) passed_counter++;
evanso 14:7419c680656f 65
evanso 14:7419c680656f 66 // prints results
evanso 18:11068b98e261 67 printf ("\nmap_draw_test passed %d tests out of 9\n",passed_counter);
evanso 14:7419c680656f 68 }
evanso 13:12276eed13ac 69
evanso 22:053c11a202e1 70 // Alien tests -----------------------------------------------------------------
evanso 22:053c11a202e1 71 void run_alien_movement_tests(){
evanso 22:053c11a202e1 72 printf ("\nTesting alien_movement_test() \n");
evanso 22:053c11a202e1 73 int passed_counter = 0;
evanso 22:053c11a202e1 74
evanso 22:053c11a202e1 75 // Runs test with all posible movment directions
evanso 22:053c11a202e1 76 if (alien_movement_test(CENTRE, 1, 0)) passed_counter++;
evanso 22:053c11a202e1 77 if (alien_movement_test(N, 1, 0)) passed_counter++;
evanso 22:053c11a202e1 78 if (alien_movement_test(NE, -1, 0)) passed_counter++;
evanso 22:053c11a202e1 79 if (alien_movement_test(E, -1, 0)) passed_counter++;
evanso 22:053c11a202e1 80 if (alien_movement_test(SE, -1, 0)) passed_counter++;
evanso 22:053c11a202e1 81 if (alien_movement_test(S, 1, 0)) passed_counter++;
evanso 22:053c11a202e1 82 if (alien_movement_test(SW, 3, 0)) passed_counter++;
evanso 22:053c11a202e1 83 if (alien_movement_test(W, 3, 0)) passed_counter++;
evanso 22:053c11a202e1 84 if (alien_movement_test(NW, 3, 0)) passed_counter++;
evanso 22:053c11a202e1 85
evanso 22:053c11a202e1 86 // prints results
evanso 22:053c11a202e1 87 printf ("\nalien_movement_test passed %d tests out of 9\n",passed_counter);
evanso 22:053c11a202e1 88 }
evanso 22:053c11a202e1 89
evanso 22:053c11a202e1 90 void run_alien_collision_test(){
evanso 22:053c11a202e1 91 printf ("\nTesting alien_collision_test() \n");
evanso 22:053c11a202e1 92 int passed_counter = 0;
evanso 22:053c11a202e1 93
evanso 22:053c11a202e1 94 // Runs test with all differnt possible inputs
evanso 22:053c11a202e1 95 if (alien_collision_test(1, 1, 10,22)) passed_counter++;
evanso 22:053c11a202e1 96 if (alien_collision_test(0, 1, 20,22)) passed_counter++;
evanso 22:053c11a202e1 97 if (alien_collision_test(1, 0, 11,22)) passed_counter++;
evanso 22:053c11a202e1 98 if (alien_collision_test(0, 0, 20,22)) passed_counter++;
evanso 22:053c11a202e1 99
evanso 22:053c11a202e1 100 // prints results
evanso 22:053c11a202e1 101 printf ("\nalien_movement_test passed %d tests out of 4\n",passed_counter);
evanso 22:053c11a202e1 102 }
evanso 15:90b6821bcf64 103
evanso 11:ab578a151f67 104 #endif