Changeset 8980 for code/branches/presentation2011/src/modules/pong
- Timestamp:
- Dec 14, 2011, 2:38:37 PM (13 years ago)
- Location:
- code/branches/presentation2011
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2011
- Property svn:mergeinfo changed
/code/branches/gamecontent (added) merged: 8893,8895,8899-8901,8904,8907,8909-8910,8922-8924,8930,8932,8941-8942,8950-8951,8956
- Property svn:mergeinfo changed
-
code/branches/presentation2011/src/modules/pong/Pong.cc
r8858 r8980 37 37 #include "core/EventIncludes.h" 38 38 #include "core/command/Executor.h" 39 #include "core/ConfigValueIncludes.h" 39 40 40 41 #include "gamestates/GSLevel.h" 42 #include "chat/ChatManager.h" 41 43 42 44 #include "PongCenterpoint.h" … … 45 47 #include "PongBot.h" 46 48 #include "PongAI.h" 47 48 49 namespace orxonox 49 50 { … … 75 76 // Set the type of Bots for this particular Gametype. 76 77 this->botclass_ = Class(PongBot); 78 this->scoreLimit_ = 10; 79 this->setConfigValues(); 77 80 } 78 81 … … 280 283 } 281 284 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); 302 this->end(); 303 } 282 304 // Restart the timer to start the ball. 283 305 this->starttimer_.startTimer(); 306 284 307 } 285 308 … … 321 344 return 0; 322 345 } 346 347 /** 348 @brief 349 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 } 323 355 } -
code/branches/presentation2011/src/modules/pong/Pong.h
r8351 r8980 81 81 void setCenterpoint(PongCenterpoint* center) 82 82 { this->center_ = center; } 83 84 PlayerInfo* getLeftPlayer() const; //!< Get the left player. 83 void setConfigValues(); //!< Makes scoreLimit configurable. 84 85 PlayerInfo* getLeftPlayer() const; //!< Get the left player. 85 86 PlayerInfo* getRightPlayer() const; //!< Get the right player. 86 87 … … 94 95 WeakPtr<PongBall> ball_; //!< The Pong ball. 95 96 WeakPtr<PongBat> bat_[2]; //!< The two bats. 96 Timer starttimer_; //!< A timer to delay the start of the game. 97 Timer starttimer_; //!< A timer to delay the start of the game. 98 int scoreLimit_; //!< If a player scored that much points, the game is ended. 97 99 }; 98 100 } -
code/branches/presentation2011/src/modules/pong/PongAI.h
r8108 r8980 80 80 void delayedMove(); //!< Is called, when a delayed move takes effect. 81 81 82 PongBall* ball_; //!< Apointer to the ball.82 WeakPtr<PongBall> ball_; //!< A weak pointer to the ball. 83 83 Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying. 84 84 float ballEndPosition_; //!< The calculated end position of the ball. -
code/branches/presentation2011/src/modules/pong/PongScore.cc
r8108 r8980 60 60 this->bShowLeftPlayer_ = false; 61 61 this->bShowRightPlayer_ = false; 62 this->player1_ = NULL; 63 this->player2_ = NULL; 62 64 } 63 65 … … 98 100 if (this->owner_ != NULL) 99 101 { 100 // Get the two players. 101 PlayerInfo* player1 = this->owner_->getLeftPlayer(); 102 PlayerInfo* player2 = this->owner_->getRightPlayer(); 103 104 std::string name1; 105 std::string name2; 106 107 std::string score1("0"); 108 std::string score2("0"); 109 110 // Save the name and score of each player as a string. 111 if (player1 != NULL) 102 if(!this->owner_->hasEnded()) 112 103 { 113 name1 = player1->getName(); 114 score1 = multi_cast<std::string>(this->owner_->getScore(player1)); 115 } 116 if (player2 != NULL) 117 { 118 name2 = player2->getName(); 119 score2 = multi_cast<std::string>(this->owner_->getScore(player2)); 104 //get the two players 105 player1_ = this->owner_->getLeftPlayer(); 106 player2_ = this->owner_->getRightPlayer(); 120 107 } 121 108 122 // Assemble the strings, depending on what should all be displayed. 123 std::string output1; 124 if (this->bShowLeftPlayer_) 109 if(this->owner_->hasStarted()) 125 110 { 126 if (this->bShowName_ && this->bShowScore_ && player1 != NULL) 127 output1 = name1 + " - " + score1; 128 else if (this->bShowScore_) 129 output1 = score1; 130 else if (this->bShowName_) 131 output1 = name1; 132 } 111 // Get the two players. 133 112 134 std::string output2; 135 if (this->bShowRightPlayer_) 136 { 137 if (this->bShowName_ && this->bShowScore_ && player2 != NULL) 113 std::string name1; 114 std::string name2; 115 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 { 146 if (this->bShowName_ && this->bShowScore_ && player2_ != NULL) 138 147 output2 = score2 + " - " + name2; 139 148 else if (this->bShowScore_) … … 143 152 } 144 153 145 std::string output("PONG"); 146 if (this->bShowName_ || this->bShowScore_) 147 { 148 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_) 149 output = output1 + ':' + output2; 150 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_) 151 output = output1 + output2; 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); 152 163 } 153 154 this->setCaption(output);155 164 } 156 165 } -
code/branches/presentation2011/src/modules/pong/PongScore.h
r8108 r8980 122 122 bool bShowLeftPlayer_; //!< Whether the left player is shown. 123 123 bool bShowRightPlayer_; //!< Whether the right player is shown. 124 PlayerInfo* player1_; //!< Store information about left player permanently. 125 PlayerInfo* player2_; //!< Same for the right player. To end the game properly. 124 126 }; 125 127 }
Note: See TracChangeset
for help on using the changeset viewer.