Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
ScoreKeeper.ccGo to the documentation of this file.00001 #include "Kodu/Keepers/ScoreKeeper.h" 00002 00003 namespace Kodu { 00004 00005 Timestamp_t ScoreChange::getTimestamp() const { 00006 return timeCreated; 00007 } 00008 00009 bool ScoreChange::operator>(const ScoreChange& rhs) { 00010 return (timeCreated > rhs.timeCreated); 00011 } 00012 00013 bool ScoreChange::operator<(const ScoreChange& rhs) { 00014 return (timeCreated < rhs.timeCreated); 00015 } 00016 00017 bool ScoreChange::operator==(const ScoreChange& rhs) { 00018 return (timeCreated == rhs.timeCreated); 00019 } 00020 00021 bool ScoreChange::operator!=(const ScoreChange& rhs) { 00022 return (!(*this == rhs)); 00023 } 00024 00025 int ScoreKeeper::addScore(const std::string& scoreKey, int value) { 00026 if (!scoreExists(scoreKey)) { 00027 registerScore(scoreKey); 00028 } 00029 scoreBoard[scoreKey] += value; 00030 // TODO (20/JUL/13) how to report a value in stdout with color using the KoduColor class 00031 std::cout << "ScoreKeeper: Score {" << scoreKey << "} = " 00032 << scoreBoard[scoreKey] << std::endl; 00033 return scoreBoard[scoreKey]; 00034 } 00035 00036 int ScoreKeeper::checkScoreValue(const std::string& scoreKey) { 00037 if (!scoreExists(scoreKey)) { 00038 registerScore(scoreKey); 00039 } 00040 return scoreBoard[scoreKey]; 00041 } 00042 00043 void ScoreKeeper::initialize() { 00044 std::cout << "Initializing score board...\n"; 00045 scoreBoard.clear(); 00046 } 00047 00048 bool ScoreKeeper::registerScore(const std::string& scoreKey) { 00049 if (!scoreExists(scoreKey)) { 00050 scoreBoard.insert(std::pair<std::string,int>(scoreKey, 0)); 00051 std::cout << "ScoreKeeper: Registering score with key {" 00052 << scoreKey << "}.\n"; 00053 } 00054 return scoreExists(scoreKey); 00055 } 00056 00057 bool ScoreKeeper::scoreExists(const std::string& scoreKey) { 00058 return (scoreBoard.count(scoreKey) > 0); 00059 } 00060 00061 int ScoreKeeper::setScore(const std::string& scoreKey, int value) { 00062 if (!scoreExists(scoreKey)) { 00063 registerScore(scoreKey); 00064 } 00065 scoreBoard[scoreKey] = value; 00066 // TODO (20/JUL/13) how to report a value in stdout with color using the KoduColor class 00067 std::cout << "ScoreKeeper: Score {" << scoreKey << "} = " 00068 << scoreBoard[scoreKey] << std::endl; 00069 return scoreBoard[scoreKey]; 00070 } 00071 00072 int ScoreKeeper::subtractScore(const std::string& scoreKey, int value) { 00073 if (!scoreExists(scoreKey)) { 00074 registerScore(scoreKey); 00075 } 00076 scoreBoard[scoreKey] -= value; 00077 // TODO (20/JUL/13) how to report a value in stdout with color using the KoduColor class 00078 std::cout << "ScoreKeeper: Score {" << scoreKey << "} = " 00079 << scoreBoard[scoreKey] << std::endl; 00080 return scoreBoard[scoreKey]; 00081 } 00082 00083 } |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3 |