This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).
Operator.h@9:54c620f7d736, 2017-04-23 (annotated)
- Committer:
- domkay97
- Date:
- Sun Apr 23 16:36:37 2017 +0000
- Revision:
- 9:54c620f7d736
- Parent:
- 8:93f18f1c1241
- Child:
- 11:48190450b7e5
Updated Comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
domkay97 | 0:3097759acb02 | 1 | #ifndef OPERATOR_H |
domkay97 | 0:3097759acb02 | 2 | #define OPERATOR_H |
domkay97 | 0:3097759acb02 | 3 | |
domkay97 | 0:3097759acb02 | 4 | #include "mbed.h" |
domkay97 | 0:3097759acb02 | 5 | #include "N5110.h" |
domkay97 | 0:3097759acb02 | 6 | #include "Display.h" |
domkay97 | 1:0f98beb0993b | 7 | #include "Controller.h" |
domkay97 | 0:3097759acb02 | 8 | |
domkay97 | 8:93f18f1c1241 | 9 | |
domkay97 | 8:93f18f1c1241 | 10 | struct Player { |
domkay97 | 8:93f18f1c1241 | 11 | float wait; /**< float for wair time */ |
domkay97 | 8:93f18f1c1241 | 12 | bool status; /**< true/flase alive or dead */ |
domkay97 | 8:93f18f1c1241 | 13 | int score; /**< score */ |
domkay97 | 8:93f18f1c1241 | 14 | }; |
domkay97 | 8:93f18f1c1241 | 15 | |
domkay97 | 0:3097759acb02 | 16 | class Operator |
domkay97 | 0:3097759acb02 | 17 | { |
domkay97 | 0:3097759acb02 | 18 | |
domkay97 | 7:5d9b9d0bc6e7 | 19 | public: |
domkay97 | 7:5d9b9d0bc6e7 | 20 | |
domkay97 | 7:5d9b9d0bc6e7 | 21 | /**Contructor*/ |
domkay97 | 0:3097759acb02 | 22 | Operator(); |
domkay97 | 7:5d9b9d0bc6e7 | 23 | |
domkay97 | 7:5d9b9d0bc6e7 | 24 | /**Destructor*/ |
domkay97 | 0:3097759acb02 | 25 | ~Operator(); |
domkay97 | 0:3097759acb02 | 26 | |
domkay97 | 0:3097759acb02 | 27 | |
domkay97 | 7:5d9b9d0bc6e7 | 28 | /** |
domkay97 | 7:5d9b9d0bc6e7 | 29 | * @brief generates a random interger to be used in the display class to represent an instruction |
domkay97 | 9:54c620f7d736 | 30 | * @param Display, N5110 |
domkay97 | 7:5d9b9d0bc6e7 | 31 | * @return void random interger |
domkay97 | 7:5d9b9d0bc6e7 | 32 | */ |
domkay97 | 7:5d9b9d0bc6e7 | 33 | int random_instruction(Display &display, N5110 &lcd); |
domkay97 | 7:5d9b9d0bc6e7 | 34 | |
domkay97 | 8:93f18f1c1241 | 35 | /** |
domkay97 | 8:93f18f1c1241 | 36 | * @brief Method to test the player |
domkay97 | 9:54c620f7d736 | 37 | * @param the player to test, Controller, Display, N5110 |
domkay97 | 8:93f18f1c1241 | 38 | * @return true/false on Success |
domkay97 | 8:93f18f1c1241 | 39 | */ |
domkay97 | 8:93f18f1c1241 | 40 | bool test_player(int nextplayer, Controller &ctrl, Display &display, N5110 &lcd); |
domkay97 | 8:93f18f1c1241 | 41 | |
domkay97 | 8:93f18f1c1241 | 42 | /** |
domkay97 | 8:93f18f1c1241 | 43 | * @brief Method to check if both players are dead |
domkay97 | 8:93f18f1c1241 | 44 | * @return true/false |
domkay97 | 8:93f18f1c1241 | 45 | */ |
domkay97 | 8:93f18f1c1241 | 46 | bool check_dead(); |
domkay97 | 8:93f18f1c1241 | 47 | |
domkay97 | 9:54c620f7d736 | 48 | /** Method performed when the user performs the RIGHT instruction on time, score is increased, lighting and sound performed. |
domkay97 | 9:54c620f7d736 | 49 | * @param the player, Controller |
domkay97 | 9:54c620f7d736 | 50 | */ |
domkay97 | 8:93f18f1c1241 | 51 | void Correct(int next_player, Controller &ctrl); |
domkay97 | 8:93f18f1c1241 | 52 | |
domkay97 | 9:54c620f7d736 | 53 | /** Method performed when the user performs the WRONG instruction on time |
domkay97 | 9:54c620f7d736 | 54 | * @param the player, Controller |
domkay97 | 9:54c620f7d736 | 55 | */ |
domkay97 | 8:93f18f1c1241 | 56 | void InCorrect(int next_player, Controller &ctrl); |
domkay97 | 8:93f18f1c1241 | 57 | |
domkay97 | 9:54c620f7d736 | 58 | /** Method to set up array of Player strut |
domkay97 | 9:54c620f7d736 | 59 | * @param the number of players to set up |
domkay97 | 9:54c620f7d736 | 60 | */ |
domkay97 | 8:93f18f1c1241 | 61 | void setup_players(int num_players); |
domkay97 | 8:93f18f1c1241 | 62 | |
domkay97 | 9:54c620f7d736 | 63 | /** Method performed when the user is too slow or performs the wrong instruction, score is displayed, game ends |
domkay97 | 9:54c620f7d736 | 64 | * @param the player, Controller |
domkay97 | 9:54c620f7d736 | 65 | */ |
domkay97 | 7:5d9b9d0bc6e7 | 66 | void Game_Over(Controller &ctrl, N5110 &lcd); |
domkay97 | 7:5d9b9d0bc6e7 | 67 | |
domkay97 | 9:54c620f7d736 | 68 | /** Method performed to chech which user it is and to swap after exch ten*/ |
domkay97 | 8:93f18f1c1241 | 69 | int check_next_player(int next_player, N5110 &lcd, Controller &ctrl, Display display); |
domkay97 | 8:93f18f1c1241 | 70 | |
domkay97 | 7:5d9b9d0bc6e7 | 71 | private: |
domkay97 | 9:54c620f7d736 | 72 | /** This methord displays and assesses score and display a performace rating for user to see. |
domkay97 | 9:54c620f7d736 | 73 | * @param N5110, score |
domkay97 | 9:54c620f7d736 | 74 | */ |
domkay97 | 7:5d9b9d0bc6e7 | 75 | void Assessment(N5110 &lcd, int score); |
domkay97 | 8:93f18f1c1241 | 76 | |
domkay97 | 9:54c620f7d736 | 77 | /** This methord displays and assesses scores when multi-player |
domkay97 | 9:54c620f7d736 | 78 | * @param N5110 |
domkay97 | 9:54c620f7d736 | 79 | */ |
domkay97 | 8:93f18f1c1241 | 80 | void MultiResults(N5110 &lcd); |
domkay97 | 8:93f18f1c1241 | 81 | |
domkay97 | 9:54c620f7d736 | 82 | /** This method counts down the next player |
domkay97 | 9:54c620f7d736 | 83 | * @param Controller, N5110, the player to display next turn |
domkay97 | 9:54c620f7d736 | 84 | */ |
domkay97 | 9:54c620f7d736 | 85 | void DisplayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player); |
domkay97 | 9:54c620f7d736 | 86 | |
domkay97 | 9:54c620f7d736 | 87 | |
domkay97 | 7:5d9b9d0bc6e7 | 88 | float freq_change; |
domkay97 | 7:5d9b9d0bc6e7 | 89 | int score; // <score to indentify users progress through game |
domkay97 | 8:93f18f1c1241 | 90 | Player myplayers[1]; //setup players |
domkay97 | 8:93f18f1c1241 | 91 | int _num_players; //set num_players |
domkay97 | 0:3097759acb02 | 92 | |
domkay97 | 0:3097759acb02 | 93 | }; |
domkay97 | 0:3097759acb02 | 94 | |
domkay97 | 0:3097759acb02 | 95 | #endif |