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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Operator.h Source File

Operator.h

00001 #ifndef OPERATOR_H
00002 #define OPERATOR_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Display.h" 
00007 #include "Controller.h"  
00008 /** Player Struct
00009 @brief This Struct stores:- whether the previous player has already lost the game or not, how much time they intially had to
00010 perform an instruction and the score they have. This struct is crucial for multiplayer.
00011 @author Dominic Kay
00012 
00013 @date April 2017
00014 */
00015 
00016 
00017 struct Player {
00018     float wait;  /**< float for wait time */
00019     bool status; /**< true/flase alive or dead */
00020     int _score; /**< score */
00021 };
00022 
00023 /** Operator Class
00024 @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). 
00025 
00026 @author Dominic Kay
00027 
00028 @date April 2017
00029 */
00030 
00031 
00032 class Operator
00033 {
00034 
00035 public: 
00036     
00037     /**Contructor*/
00038     Operator();
00039     
00040     /**Destructor*/
00041     ~Operator();
00042 
00043 
00044  /**
00045      * @brief generates a random integer to be used in the display class to represent an instruction
00046      * @param Display, N5110
00047      * @return random integer
00048      */
00049     int random_instruction(Display &display, N5110 &lcd);  
00050 
00051 /** 
00052     *  @brief Method to test the player 
00053     *  @param the player to test, Controller, Display, N5110
00054     *  @return true/false on Success
00055     */
00056     bool test_player(int nextplayer, Controller &ctrl, Display &display, N5110 &lcd);
00057 
00058 /** 
00059     *  @brief Method to check if both players are dead 
00060     *  @return true/false
00061     */
00062     bool both_dead();
00063 
00064 /** Method performed when the user performs the RIGHT instruction on time, score is increased, lighting and sound performed.
00065     *  @param the player, Controller
00066     */
00067     void correct(int current_player, Controller &ctrl);  
00068 
00069 /** Method performed when the user performs the WRONG instruction on time 
00070     *  @param the player, Controller
00071     */
00072     void inCorrect(int current_player, Controller &ctrl);  
00073 
00074 /** Method to set up array of Player strut 
00075     *  @param the number of players to set up
00076     */
00077     void setup_players(int num_players);
00078             
00079 /** Method performed when the user is too slow or performs the wrong instruction, score is displayed, game ends 
00080     *  @param the player, Controller
00081     */
00082     void gameOver(Controller &ctrl, N5110 &lcd);
00083     
00084 /** Method performed to check which user it is and to swap after every ten actions*/
00085     int check_next_player(int current_player, N5110 &lcd, Controller &ctrl, Display display);
00086 
00087 private:  
00088     /** This method displays and assesses score and display a performace rating for user to see.
00089     *  @param N5110, score
00090     */    
00091     void _assessment(N5110 &lcd, int score); 
00092  
00093     /** This method displays and assesses scores when multi-player
00094     *  @param N5110
00095     */
00096    void _multiResults(N5110 &lcd);
00097   
00098     /** This method counts down the next player 
00099     *  @param Controller, N5110, the player to display next turn
00100     */ 
00101    void _displayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player);
00102    
00103        
00104     float _freqChange;
00105     int _score; // <score to indentify users progress through game
00106     Player myplayers[1]; //setup players 
00107     int _num_players;    //set num_players
00108     
00109 };
00110 
00111 #endif