This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).

Committer:
domkay97
Date:
Tue May 02 18:05:38 2017 +0000
Revision:
13:1684970587ce
Parent:
12:bdaf4e1d615e
Changed some method names, added more comments

Who changed what in which revision?

UserRevisionLine numberNew 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 11:48190450b7e5 8 /** Player Struct
domkay97 11:48190450b7e5 9 @brief This Struct stores:- whether the previous player has already lost the game or not, how much time they intially had to
domkay97 11:48190450b7e5 10 perform an instruction and the score they have. This struct is crucial for multiplayer.
domkay97 11:48190450b7e5 11 @author Dominic Kay
domkay97 11:48190450b7e5 12
domkay97 11:48190450b7e5 13 @date April 2017
domkay97 11:48190450b7e5 14 */
domkay97 0:3097759acb02 15
domkay97 8:93f18f1c1241 16
domkay97 8:93f18f1c1241 17 struct Player {
domkay97 11:48190450b7e5 18 float wait; /**< float for wait time */
domkay97 8:93f18f1c1241 19 bool status; /**< true/flase alive or dead */
domkay97 11:48190450b7e5 20 int _score; /**< score */
domkay97 8:93f18f1c1241 21 };
domkay97 8:93f18f1c1241 22
domkay97 11:48190450b7e5 23 /** Operator Class
domkay97 13:1684970587ce 24 @brief This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).
domkay97 11:48190450b7e5 25
domkay97 11:48190450b7e5 26 @author Dominic Kay
domkay97 11:48190450b7e5 27
domkay97 11:48190450b7e5 28 @date April 2017
domkay97 11:48190450b7e5 29 */
domkay97 11:48190450b7e5 30
domkay97 11:48190450b7e5 31
domkay97 0:3097759acb02 32 class Operator
domkay97 0:3097759acb02 33 {
domkay97 0:3097759acb02 34
domkay97 7:5d9b9d0bc6e7 35 public:
domkay97 7:5d9b9d0bc6e7 36
domkay97 7:5d9b9d0bc6e7 37 /**Contructor*/
domkay97 0:3097759acb02 38 Operator();
domkay97 7:5d9b9d0bc6e7 39
domkay97 7:5d9b9d0bc6e7 40 /**Destructor*/
domkay97 0:3097759acb02 41 ~Operator();
domkay97 0:3097759acb02 42
domkay97 0:3097759acb02 43
domkay97 7:5d9b9d0bc6e7 44 /**
domkay97 12:bdaf4e1d615e 45 * @brief generates a random integer to be used in the display class to represent an instruction
domkay97 9:54c620f7d736 46 * @param Display, N5110
domkay97 12:bdaf4e1d615e 47 * @return random integer
domkay97 7:5d9b9d0bc6e7 48 */
domkay97 7:5d9b9d0bc6e7 49 int random_instruction(Display &display, N5110 &lcd);
domkay97 7:5d9b9d0bc6e7 50
domkay97 8:93f18f1c1241 51 /**
domkay97 8:93f18f1c1241 52 * @brief Method to test the player
domkay97 9:54c620f7d736 53 * @param the player to test, Controller, Display, N5110
domkay97 8:93f18f1c1241 54 * @return true/false on Success
domkay97 8:93f18f1c1241 55 */
domkay97 8:93f18f1c1241 56 bool test_player(int nextplayer, Controller &ctrl, Display &display, N5110 &lcd);
domkay97 8:93f18f1c1241 57
domkay97 8:93f18f1c1241 58 /**
domkay97 8:93f18f1c1241 59 * @brief Method to check if both players are dead
domkay97 8:93f18f1c1241 60 * @return true/false
domkay97 8:93f18f1c1241 61 */
domkay97 13:1684970587ce 62 bool both_dead();
domkay97 8:93f18f1c1241 63
domkay97 9:54c620f7d736 64 /** Method performed when the user performs the RIGHT instruction on time, score is increased, lighting and sound performed.
domkay97 9:54c620f7d736 65 * @param the player, Controller
domkay97 9:54c620f7d736 66 */
domkay97 13:1684970587ce 67 void correct(int current_player, Controller &ctrl);
domkay97 8:93f18f1c1241 68
domkay97 9:54c620f7d736 69 /** Method performed when the user performs the WRONG instruction on time
domkay97 9:54c620f7d736 70 * @param the player, Controller
domkay97 9:54c620f7d736 71 */
domkay97 13:1684970587ce 72 void inCorrect(int current_player, Controller &ctrl);
domkay97 8:93f18f1c1241 73
domkay97 9:54c620f7d736 74 /** Method to set up array of Player strut
domkay97 9:54c620f7d736 75 * @param the number of players to set up
domkay97 9:54c620f7d736 76 */
domkay97 8:93f18f1c1241 77 void setup_players(int num_players);
domkay97 8:93f18f1c1241 78
domkay97 9:54c620f7d736 79 /** Method performed when the user is too slow or performs the wrong instruction, score is displayed, game ends
domkay97 9:54c620f7d736 80 * @param the player, Controller
domkay97 9:54c620f7d736 81 */
domkay97 11:48190450b7e5 82 void gameOver(Controller &ctrl, N5110 &lcd);
domkay97 7:5d9b9d0bc6e7 83
domkay97 11:48190450b7e5 84 /** Method performed to check which user it is and to swap after every ten actions*/
domkay97 13:1684970587ce 85 int check_next_player(int current_player, N5110 &lcd, Controller &ctrl, Display display);
domkay97 12:bdaf4e1d615e 86
domkay97 7:5d9b9d0bc6e7 87 private:
domkay97 12:bdaf4e1d615e 88 /** This method displays and assesses score and display a performace rating for user to see.
domkay97 9:54c620f7d736 89 * @param N5110, score
domkay97 9:54c620f7d736 90 */
domkay97 11:48190450b7e5 91 void _assessment(N5110 &lcd, int score);
domkay97 8:93f18f1c1241 92
domkay97 12:bdaf4e1d615e 93 /** This method displays and assesses scores when multi-player
domkay97 9:54c620f7d736 94 * @param N5110
domkay97 9:54c620f7d736 95 */
domkay97 11:48190450b7e5 96 void _multiResults(N5110 &lcd);
domkay97 8:93f18f1c1241 97
domkay97 9:54c620f7d736 98 /** This method counts down the next player
domkay97 9:54c620f7d736 99 * @param Controller, N5110, the player to display next turn
domkay97 9:54c620f7d736 100 */
domkay97 11:48190450b7e5 101 void _displayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player);
domkay97 9:54c620f7d736 102
domkay97 9:54c620f7d736 103
domkay97 11:48190450b7e5 104 float _freqChange;
domkay97 11:48190450b7e5 105 int _score; // <score to indentify users progress through game
domkay97 8:93f18f1c1241 106 Player myplayers[1]; //setup players
domkay97 8:93f18f1c1241 107 int _num_players; //set num_players
domkay97 0:3097759acb02 108
domkay97 0:3097759acb02 109 };
domkay97 0:3097759acb02 110
domkay97 0:3097759acb02 111 #endif