contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameTests/tests.cpp@40:13b8467526d0, 2019-05-07 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Tue May 07 15:17:21 2019 +0000
- Revision:
- 40:13b8467526d0
- Parent:
- 33:24ef796ff2c8
Final Submission. I have read and agreed with Statement of Academic Integrity
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OmarAlebiary | 26:35714debc45f | 1 | #include "tests.h" |
OmarAlebiary | 28:39607fb67e88 | 2 | |
OmarAlebiary | 28:39607fb67e88 | 3 | |
OmarAlebiary | 33:24ef796ff2c8 | 4 | //default constructor of the class |
OmarAlebiary | 33:24ef796ff2c8 | 5 | tests::tests(){ |
OmarAlebiary | 33:24ef796ff2c8 | 6 | } |
OmarAlebiary | 33:24ef796ff2c8 | 7 | |
OmarAlebiary | 33:24ef796ff2c8 | 8 | //destructor of the class |
OmarAlebiary | 33:24ef796ff2c8 | 9 | tests::~tests(){ |
OmarAlebiary | 28:39607fb67e88 | 10 | |
OmarAlebiary | 28:39607fb67e88 | 11 | } |
OmarAlebiary | 29:e660274d8222 | 12 | |
OmarAlebiary | 33:24ef796ff2c8 | 13 | //calls the welcome menu to be tested |
OmarAlebiary | 26:35714debc45f | 14 | void tests::test_welcomeMenu(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 26:35714debc45f | 15 | menu.welcomeMenu(pad,lcd); |
OmarAlebiary | 26:35714debc45f | 16 | } |
OmarAlebiary | 26:35714debc45f | 17 | |
OmarAlebiary | 33:24ef796ff2c8 | 18 | //calls the play wecome melody to be tested |
OmarAlebiary | 28:39607fb67e88 | 19 | void tests::test_Play_Welcome_Melody(Gamepad &pad){ |
OmarAlebiary | 28:39607fb67e88 | 20 | Game_Tones.Play_Welcome_Melody(pad); |
OmarAlebiary | 26:35714debc45f | 21 | } |
OmarAlebiary | 28:39607fb67e88 | 22 | |
OmarAlebiary | 33:24ef796ff2c8 | 23 | //tests the end of game display |
OmarAlebiary | 28:39607fb67e88 | 24 | void tests::test_End_Game_Melody(Gamepad &pad){ |
OmarAlebiary | 28:39607fb67e88 | 25 | Game_Tones.End_Game_Melody(pad); |
OmarAlebiary | 33:24ef796ff2c8 | 26 | } |
OmarAlebiary | 33:24ef796ff2c8 | 27 | |
OmarAlebiary | 33:24ef796ff2c8 | 28 | //tests the draw menu screen |
OmarAlebiary | 26:35714debc45f | 29 | void tests::test_drawMenu(N5110 &lcd,Gamepad &pad){ |
OmarAlebiary | 26:35714debc45f | 30 | menu.drawMenu(lcd,pad); |
OmarAlebiary | 33:24ef796ff2c8 | 31 | } |
OmarAlebiary | 33:24ef796ff2c8 | 32 | //tests the credits page in the menu |
OmarAlebiary | 26:35714debc45f | 33 | void tests::test_credits_page(N5110 &lcd,Gamepad &pad){ |
OmarAlebiary | 26:35714debc45f | 34 | menu.credits(lcd,pad); |
OmarAlebiary | 26:35714debc45f | 35 | } |
OmarAlebiary | 26:35714debc45f | 36 | |
OmarAlebiary | 33:24ef796ff2c8 | 37 | //tests the loading page after the welcome menu |
OmarAlebiary | 26:35714debc45f | 38 | void tests::test_loading_menu(N5110 &lcd){ |
OmarAlebiary | 26:35714debc45f | 39 | menu.loading_menu(lcd); |
OmarAlebiary | 26:35714debc45f | 40 | } |
OmarAlebiary | 26:35714debc45f | 41 | |
OmarAlebiary | 33:24ef796ff2c8 | 42 | //tests the instructions |
OmarAlebiary | 26:35714debc45f | 43 | void tests::test_InstructionsMenu(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 26:35714debc45f | 44 | menu.InstructionsMenu(pad,lcd); |
OmarAlebiary | 26:35714debc45f | 45 | } |
OmarAlebiary | 26:35714debc45f | 46 | |
OmarAlebiary | 33:24ef796ff2c8 | 47 | //tests the joystick position in the game |
OmarAlebiary | 29:e660274d8222 | 48 | bool tests::test_Joystick_position(Gamepad &pad){ |
OmarAlebiary | 26:35714debc45f | 49 | |
OmarAlebiary | 29:e660274d8222 | 50 | Direction d=pad.get_direction();//assigning the object d to the method to get the joystick direction |
OmarAlebiary | 29:e660274d8222 | 51 | |
OmarAlebiary | 29:e660274d8222 | 52 | if( (d==E||pad.check_event(Gamepad::R_PRESSED) == true )){//statement to check if the joystick moved right |
OmarAlebiary | 33:24ef796ff2c8 | 53 | printf("its Right\n");//prints its right on the coolterm |
OmarAlebiary | 33:24ef796ff2c8 | 54 | return true;// returns true if the condition is met |
OmarAlebiary | 29:e660274d8222 | 55 | } |
OmarAlebiary | 29:e660274d8222 | 56 | else if( (d==W ||pad.check_event(Gamepad::L_PRESSED) == true )){//statement to check if the joystick moved left |
OmarAlebiary | 33:24ef796ff2c8 | 57 | printf("its left\n");//prints its left on the coolterm |
OmarAlebiary | 33:24ef796ff2c8 | 58 | return true;// returns true if the condition is met |
OmarAlebiary | 29:e660274d8222 | 59 | } |
OmarAlebiary | 29:e660274d8222 | 60 | else if(d==CENTRE){//statement to check if the joystick position is center |
OmarAlebiary | 33:24ef796ff2c8 | 61 | printf("its center\n");//prints its centre on the coolterm |
OmarAlebiary | 33:24ef796ff2c8 | 62 | return true;// returns true if the condition is met |
OmarAlebiary | 29:e660274d8222 | 63 | } |
OmarAlebiary | 33:24ef796ff2c8 | 64 | return false;// returns false if all the conditions are not met |
OmarAlebiary | 29:e660274d8222 | 65 | } |
OmarAlebiary | 29:e660274d8222 | 66 | |
OmarAlebiary | 33:24ef796ff2c8 | 67 | //tests the randomly genrated enemy |
OmarAlebiary | 29:e660274d8222 | 68 | bool tests::test_Generate_New_Enemy(){ |
OmarAlebiary | 29:e660274d8222 | 69 | |
OmarAlebiary | 29:e660274d8222 | 70 | srand(time(NULL));//seeding the random function |
OmarAlebiary | 29:e660274d8222 | 71 | |
OmarAlebiary | 29:e660274d8222 | 72 | int second_enemy_position = (rand() % 3)+1;//generates a random number from 1 to 3 |
OmarAlebiary | 33:24ef796ff2c8 | 73 | printf("%d",second_enemy_position);//return true if random generated number is between(1->3) |
OmarAlebiary | 29:e660274d8222 | 74 | if(second_enemy_position==1||second_enemy_position==2||second_enemy_position==3){ |
OmarAlebiary | 33:24ef796ff2c8 | 75 | return true;// returns true if any of the conditions are met |
OmarAlebiary | 33:24ef796ff2c8 | 76 | } |
OmarAlebiary | 33:24ef796ff2c8 | 77 | return false;// returns false if none of the conditions are met |
OmarAlebiary | 29:e660274d8222 | 78 | } |
OmarAlebiary | 29:e660274d8222 | 79 | |
OmarAlebiary | 29:e660274d8222 | 80 | //testing game loop |
OmarAlebiary | 26:35714debc45f | 81 | void tests::test_Game_Loop(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 33:24ef796ff2c8 | 82 | while(1){//inifinite loop to test the gameplay |
OmarAlebiary | 26:35714debc45f | 83 | Rocket_Racing.Game_Loop(lcd,pad); |
OmarAlebiary | 33:24ef796ff2c8 | 84 | } |
OmarAlebiary | 33:24ef796ff2c8 | 85 | } |
OmarAlebiary | 33:24ef796ff2c8 | 86 | |
OmarAlebiary | 33:24ef796ff2c8 | 87 | // create object and specifiy pins |
OmarAlebiary | 33:24ef796ff2c8 | 88 | FXOS8700CQ deviceee(I2C_SDA,I2C_SCL); |
OmarAlebiary | 33:24ef796ff2c8 | 89 | |
OmarAlebiary | 33:24ef796ff2c8 | 90 | bool tests::test_accelerometer_position(Gamepad &pad){ |
OmarAlebiary | 33:24ef796ff2c8 | 91 | //calls the get_pitch_angle method to get angles |
OmarAlebiary | 33:24ef796ff2c8 | 92 | float pitchAngle = deviceee.get_pitch_angle(); |
OmarAlebiary | 33:24ef796ff2c8 | 93 | //statement to check if the gamepad rolled to the right |
OmarAlebiary | 33:24ef796ff2c8 | 94 | if( (pitchAngle > 100)){ |
OmarAlebiary | 33:24ef796ff2c8 | 95 | return true; |
OmarAlebiary | 33:24ef796ff2c8 | 96 | // printf("its Right\n"); |
OmarAlebiary | 26:35714debc45f | 97 | } |
OmarAlebiary | 33:24ef796ff2c8 | 98 | //statement to check if the gamepad rolled to the left |
OmarAlebiary | 33:24ef796ff2c8 | 99 | else if( (pitchAngle < 90 )){ |
OmarAlebiary | 33:24ef796ff2c8 | 100 | return true; |
OmarAlebiary | 33:24ef796ff2c8 | 101 | // printf("its left\n"); |
OmarAlebiary | 33:24ef796ff2c8 | 102 | } |
OmarAlebiary | 33:24ef796ff2c8 | 103 | else {//returns false if not rolled right or left |
OmarAlebiary | 33:24ef796ff2c8 | 104 | return false; |
OmarAlebiary | 33:24ef796ff2c8 | 105 | } |
OmarAlebiary | 33:24ef796ff2c8 | 106 | } |
OmarAlebiary | 33:24ef796ff2c8 | 107 | |
OmarAlebiary | 33:24ef796ff2c8 | 108 | |
OmarAlebiary | 33:24ef796ff2c8 | 109 | bool tests::test_check_button_pressed(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 33:24ef796ff2c8 | 110 | if (pad.check_event(Gamepad::A_PRESSED) == true){//if A presed |
OmarAlebiary | 33:24ef796ff2c8 | 111 | printf("A pressed working"); |
OmarAlebiary | 33:24ef796ff2c8 | 112 | return true;//returns true if condition met |
OmarAlebiary | 33:24ef796ff2c8 | 113 | }else if (pad.check_event(Gamepad::B_PRESSED) == true){//if B presed |
OmarAlebiary | 33:24ef796ff2c8 | 114 | printf("B pressed working"); |
OmarAlebiary | 33:24ef796ff2c8 | 115 | return true;//returns true if condition met |
OmarAlebiary | 33:24ef796ff2c8 | 116 | }else if (pad.check_event(Gamepad::Y_PRESSED) == true){//if Y presed |
OmarAlebiary | 33:24ef796ff2c8 | 117 | printf("Y pressed working"); |
OmarAlebiary | 33:24ef796ff2c8 | 118 | return true;//returns true if condition met |
OmarAlebiary | 33:24ef796ff2c8 | 119 | }else if (pad.check_event(Gamepad::X_PRESSED) == true){//if X presed |
OmarAlebiary | 33:24ef796ff2c8 | 120 | printf("X pressed working"); |
OmarAlebiary | 33:24ef796ff2c8 | 121 | return true;//returns true if condition met |
OmarAlebiary | 33:24ef796ff2c8 | 122 | } |
OmarAlebiary | 33:24ef796ff2c8 | 123 | return false;//returns false if condition not met |
OmarAlebiary | 26:35714debc45f | 124 | } |