Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ScoreKeeper.h

Go to the documentation of this file.
00001 #ifndef SCORE_KEEPER_H_
00002 #define SCORE_KEEPER_H_
00003 
00004 // Tekkodu Library
00005 #include "Kodu/General/GeneralFncs.h"
00006 #include "Kodu/General/GeneralMacros.h"
00007 #include "Kodu/Primitives/KoduActionScore.h"
00008 
00009 // C++ Library
00010 #include <iostream>
00011 #include <string>
00012 
00013 namespace Kodu {
00014     //! The timestamp
00015     typedef unsigned long Timestamp_t;
00016     
00017     // Forward declare the KoduActionScore class (will eliminate cyclic dependencies between
00018     // included files)
00019     class KoduActionScore;
00020 
00021     class ScoreChange {
00022     public:
00023         //! Constructor
00024         ScoreChange(KoduActionScore::ScoringType_t scoreOp, const std::string& kDesignator,
00025             unsigned int val)
00026           : operationType(scoreOp),
00027             designator(kDesignator),
00028             value(val),
00029             timeCreated(0)
00030         {
00031             timeCreated = GeneralFncs::getTime();
00032         }
00033 
00034         //! Copy constructor
00035         ScoreChange(const ScoreChange& kChange)
00036           : operationType(kChange.operationType),
00037             designator(kChange.designator),
00038             value(kChange.value),
00039             timeCreated(kChange.timeCreated)
00040         { }
00041 
00042         //! Destructor
00043         ~ScoreChange() {
00044             // no explicit implementation
00045         }
00046 
00047         //! Assignment operator
00048         ScoreChange& operator=(const ScoreChange& kChange) {
00049             if (this != &kChange) {
00050                 operationType = kChange.operationType;
00051                 designator = kChange.designator;
00052                 value = kChange.value;
00053                 timeCreated = kChange.timeCreated;
00054             }
00055             return *this;
00056         }
00057 
00058         Timestamp_t getTimestamp() const;
00059 
00060         //! Overloaded greater than operator
00061         bool operator>(const ScoreChange&);
00062 
00063         //! Overloaded less than operator
00064         bool operator<(const ScoreChange&);
00065 
00066         //! Overloaded equal to operator
00067         bool operator==(const ScoreChange&);
00068 
00069         //! Overloaded not equal to operator
00070         bool operator!=(const ScoreChange&);
00071 
00072         // The ScoreKeeper class can directly access all the members of this class
00073         friend class ScoreKeeper;
00074     
00075         KoduActionScore::ScoringType_t operationType; //!< The operation type (e.g. add, set, subtract)
00076         std::string designator;     //!< The score designator (color or score letter)
00077         unsigned int value;         //!< The value to set, substract, or add
00078 
00079     private:
00080         Timestamp_t timeCreated;    //!< The approximate time the score was created
00081     };
00082 
00083     //! Score Keeper
00084     class ScoreKeeper {
00085     public:
00086         //! Constructor
00087         ScoreKeeper()
00088           : scoreBoard()
00089         { }
00090 
00091         //! Destructor
00092         ~ScoreKeeper() {
00093             scoreBoard.clear();
00094         }
00095 
00096         //! Assignment operator
00097         ScoreKeeper& operator=(const ScoreKeeper& kKeeper) {
00098             if (this != &kKeeper) {
00099                 scoreBoard = kKeeper.scoreBoard;
00100             }
00101             return *this;
00102         }
00103 
00104         //! Adds to a particular score
00105         int addScore(const std::string&, int);
00106         
00107         //! Checks the value of a particular score
00108         int checkScoreValue(const std::string&);
00109 
00110         //! (Re)Initializes the score board
00111         void initialize();
00112 
00113         //! Registers an entry for a new score based on the key provided
00114         bool registerScore(const std::string&);
00115         
00116         //! Checks if a particular score type (identified by color+letter key) exists
00117         bool scoreExists(const std::string&);
00118 
00119         //! Sets a particular score
00120         int setScore(const std::string&, int);
00121         
00122         //! Subtracts from a particular score
00123         int subtractScore(const std::string&, int);
00124 
00125     private:
00126         //! Disallows the copy constructor and assignment operator
00127         DISALLOW_COPY(ScoreKeeper);
00128 
00129         //! Contains all the global scores
00130         std::map<std::string, int> scoreBoard;
00131     };
00132 
00133 } // end of Kodu namespace
00134 
00135 #endif // SCORE_KEEPER_H_

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3