Changeset 9285 for code/branches/pCuts/src
- Timestamp:
- Jun 10, 2012, 5:03:16 PM (13 years ago)
- Location:
- code/branches/pCuts/src/modules/pong
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/src/modules/pong/Pong.cc
r9090 r9285 76 76 // Set the type of Bots for this particular Gametype. 77 77 this->botclass_ = Class(PongBot); 78 78 79 this->scoreLimit_ = 10; 79 80 this->setConfigValues(); … … 88 89 if (this->isInitialized()) 89 90 this->cleanup(); 91 } 92 93 void Pong::setConfigValues() 94 { 95 SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins."); 90 96 } 91 97 … … 283 289 } 284 290 285 // If a palyer gets 21 points, he won the game -> end of game 286 287 PlayerInfo* player1 = this->getLeftPlayer(); 288 PlayerInfo* player2 = this->getRightPlayer(); 289 if(player1==NULL||player2==NULL) return; //safety 290 if(this->getScore(player1) >= scoreLimit_) 291 { 292 std::string name1=player1->getName(); 293 std::string message(name1 + " has won!"); 294 ChatManager::message(message); 295 this->end(); 296 } 297 else if(this->getScore(player2) >= scoreLimit_) 298 { 299 std::string name2=player2->getName(); 300 std::string message2(name2 + " has won!"); 301 ChatManager::message(message2); 291 // If a player gets enough points, he won the game -> end of game 292 PlayerInfo* winningPlayer = NULL; 293 if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_) 294 winningPlayer = this->getLeftPlayer(); 295 else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_) 296 winningPlayer = this->getRightPlayer(); 297 298 if (winningPlayer) 299 { 300 ChatManager::message(winningPlayer->getName() + " has won!"); 302 301 this->end(); 303 302 } 303 304 304 // Restart the timer to start the ball. 305 305 this->starttimer_.startTimer(); 306 307 306 } 308 307 … … 344 343 return 0; 345 344 } 346 347 /**348 @brief349 Make scoreLimit_ configurable e.g. in the menu.350 */351 void Pong::setConfigValues()352 {353 SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");354 }355 345 } -
code/branches/pCuts/src/modules/pong/Pong.h
r9090 r9285 82 82 { this->center_ = center; } 83 83 void setConfigValues(); //!< Makes scoreLimit configurable. 84 84 85 85 PlayerInfo* getLeftPlayer() const; //!< Get the left player. 86 86 PlayerInfo* getRightPlayer() const; //!< Get the right player. -
code/branches/pCuts/src/modules/pong/PongScore.cc
r9090 r9285 60 60 this->bShowLeftPlayer_ = false; 61 61 this->bShowRightPlayer_ = false; 62 this->player1_ = NULL;63 this->player2_ = NULL;64 62 } 65 63 … … 100 98 if (this->owner_ != NULL) 101 99 { 102 if(!this->owner_->hasEnded())100 if (!this->owner_->hasEnded()) 103 101 { 104 // get the two players102 // Get the two players. 105 103 player1_ = this->owner_->getLeftPlayer(); 106 104 player2_ = this->owner_->getRightPlayer(); 107 105 } 108 106 109 if(this->owner_->hasStarted()) 107 std::string name1; 108 std::string name2; 109 110 std::string score1("0"); 111 std::string score2("0"); 112 113 // Save the name and score of each player as a string. 114 if (player1_ != NULL) 110 115 { 111 // Get the two players. 116 name1 = player1_->getName(); 117 score1 = multi_cast<std::string>(this->owner_->getScore(player1_)); 118 } 119 if (player2_ != NULL) 120 { 121 name2 = player2_->getName(); 122 score2 = multi_cast<std::string>(this->owner_->getScore(player2_)); 123 } 112 124 113 std::string name1; 114 std::string name2; 125 // Assemble the strings, depending on what should all be displayed. 126 std::string output1; 127 if (this->bShowLeftPlayer_) 128 { 129 if (this->bShowName_ && this->bShowScore_ && player1_ != NULL) 130 output1 = name1 + " - " + score1; 131 else if (this->bShowScore_) 132 output1 = score1; 133 else if (this->bShowName_) 134 output1 = name1; 135 } 115 136 116 std::string score1("0"); 117 std::string score2("0"); 118 119 // Save the name and score of each player as a string. 120 if (player1_ != NULL) 121 { 122 name1 = player1_->getName(); 123 score1 = multi_cast<std::string>(this->owner_->getScore(player1_)); 124 } 125 if (player2_ != NULL) 126 { 127 name2 = player2_->getName(); 128 score2 = multi_cast<std::string>(this->owner_->getScore(player2_)); 129 } 130 131 // Assemble the strings, depending on what should all be displayed. 132 std::string output1; 133 if (this->bShowLeftPlayer_) 134 { 135 if (this->bShowName_ && this->bShowScore_ && player1_ != NULL) 136 output1 = name1 + " - " + score1; 137 else if (this->bShowScore_) 138 output1 = score1; 139 else if (this->bShowName_) 140 output1 = name1; 141 } 142 143 std::string output2; 144 if (this->bShowRightPlayer_) 145 { 137 std::string output2; 138 if (this->bShowRightPlayer_) 139 { 146 140 if (this->bShowName_ && this->bShowScore_ && player2_ != NULL) 147 141 output2 = score2 + " - " + name2; … … 152 146 } 153 147 154 std::string output("PONG"); 155 if (this->bShowName_ || this->bShowScore_) 156 { 157 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_) 158 output = output1 + ':' + output2; 159 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_) 160 output = output1 + output2; 161 } 162 this->setCaption(output); 148 std::string output("PONG"); 149 if (this->bShowName_ || this->bShowScore_) 150 { 151 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_) 152 output = output1 + ':' + output2; 153 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_) 154 output = output1 + output2; 163 155 } 156 157 this->setCaption(output); 164 158 } 165 159 }
Note: See TracChangeset
for help on using the changeset viewer.