[Orxonox-commit 4614] r9285 - code/branches/pCuts/src/modules/pong
jo at orxonox.net
jo at orxonox.net
Sun Jun 10 17:03:17 CEST 2012
Author: jo
Date: 2012-06-10 17:03:16 +0200 (Sun, 10 Jun 2012)
New Revision: 9285
Modified:
code/branches/pCuts/src/modules/pong/Pong.cc
code/branches/pCuts/src/modules/pong/Pong.h
code/branches/pCuts/src/modules/pong/PongScore.cc
Log:
Adaptions for easier merge.
Modified: code/branches/pCuts/src/modules/pong/Pong.cc
===================================================================
--- code/branches/pCuts/src/modules/pong/Pong.cc 2012-06-10 12:09:14 UTC (rev 9284)
+++ code/branches/pCuts/src/modules/pong/Pong.cc 2012-06-10 15:03:16 UTC (rev 9285)
@@ -75,6 +75,7 @@
// Set the type of Bots for this particular Gametype.
this->botclass_ = Class(PongBot);
+
this->scoreLimit_ = 10;
this->setConfigValues();
}
@@ -89,6 +90,11 @@
this->cleanup();
}
+ void Pong::setConfigValues()
+ {
+ SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
+ }
+
/**
@brief
Cleans up the Gametype by destroying the ball and the bats.
@@ -282,28 +288,21 @@
this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
}
- // If a palyer gets 21 points, he won the game -> end of game
+ // If a player gets enough points, he won the game -> end of game
+ PlayerInfo* winningPlayer = NULL;
+ if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_)
+ winningPlayer = this->getLeftPlayer();
+ else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_)
+ winningPlayer = this->getRightPlayer();
- PlayerInfo* player1 = this->getLeftPlayer();
- PlayerInfo* player2 = this->getRightPlayer();
- if(player1==NULL||player2==NULL) return; //safety
- if(this->getScore(player1) >= scoreLimit_)
+ if (winningPlayer)
{
- std::string name1=player1->getName();
- std::string message(name1 + " has won!");
- ChatManager::message(message);
- this->end();
- }
- else if(this->getScore(player2) >= scoreLimit_)
- {
- std::string name2=player2->getName();
- std::string message2(name2 + " has won!");
- ChatManager::message(message2);
+ ChatManager::message(winningPlayer->getName() + " has won!");
this->end();
}
+
// Restart the timer to start the ball.
this->starttimer_.startTimer();
-
}
/**
@@ -343,13 +342,4 @@
else
return 0;
}
-
- /**
- @brief
- Make scoreLimit_ configurable e.g. in the menu.
- */
- void Pong::setConfigValues()
- {
- SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
- }
}
Modified: code/branches/pCuts/src/modules/pong/Pong.h
===================================================================
--- code/branches/pCuts/src/modules/pong/Pong.h 2012-06-10 12:09:14 UTC (rev 9284)
+++ code/branches/pCuts/src/modules/pong/Pong.h 2012-06-10 15:03:16 UTC (rev 9285)
@@ -81,7 +81,7 @@
void setCenterpoint(PongCenterpoint* center)
{ this->center_ = center; }
void setConfigValues(); //!< Makes scoreLimit configurable.
-
+
PlayerInfo* getLeftPlayer() const; //!< Get the left player.
PlayerInfo* getRightPlayer() const; //!< Get the right player.
Modified: code/branches/pCuts/src/modules/pong/PongScore.cc
===================================================================
--- code/branches/pCuts/src/modules/pong/PongScore.cc 2012-06-10 12:09:14 UTC (rev 9284)
+++ code/branches/pCuts/src/modules/pong/PongScore.cc 2012-06-10 15:03:16 UTC (rev 9285)
@@ -59,8 +59,6 @@
this->bShowScore_ = false;
this->bShowLeftPlayer_ = false;
this->bShowRightPlayer_ = false;
- this->player1_ = NULL;
- this->player2_ = NULL;
}
/**
@@ -99,50 +97,46 @@
// If the owner is set. The owner being a Pong game.
if (this->owner_ != NULL)
{
- if(!this->owner_->hasEnded())
+ if (!this->owner_->hasEnded())
{
- //get the two players
+ // Get the two players.
player1_ = this->owner_->getLeftPlayer();
player2_ = this->owner_->getRightPlayer();
}
- if(this->owner_->hasStarted())
- {
- // Get the two players.
+ std::string name1;
+ std::string name2;
- std::string name1;
- std::string name2;
+ std::string score1("0");
+ std::string score2("0");
- std::string score1("0");
- std::string score2("0");
+ // Save the name and score of each player as a string.
+ if (player1_ != NULL)
+ {
+ name1 = player1_->getName();
+ score1 = multi_cast<std::string>(this->owner_->getScore(player1_));
+ }
+ if (player2_ != NULL)
+ {
+ name2 = player2_->getName();
+ score2 = multi_cast<std::string>(this->owner_->getScore(player2_));
+ }
- // Save the name and score of each player as a string.
- if (player1_ != NULL)
- {
- name1 = player1_->getName();
- score1 = multi_cast<std::string>(this->owner_->getScore(player1_));
- }
- if (player2_ != NULL)
- {
- name2 = player2_->getName();
- score2 = multi_cast<std::string>(this->owner_->getScore(player2_));
- }
+ // Assemble the strings, depending on what should all be displayed.
+ std::string output1;
+ if (this->bShowLeftPlayer_)
+ {
+ if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)
+ output1 = name1 + " - " + score1;
+ else if (this->bShowScore_)
+ output1 = score1;
+ else if (this->bShowName_)
+ output1 = name1;
+ }
- // Assemble the strings, depending on what should all be displayed.
- std::string output1;
- if (this->bShowLeftPlayer_)
- {
- if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)
- output1 = name1 + " - " + score1;
- else if (this->bShowScore_)
- output1 = score1;
- else if (this->bShowName_)
- output1 = name1;
- }
-
- std::string output2;
- if (this->bShowRightPlayer_)
- {
+ std::string output2;
+ if (this->bShowRightPlayer_)
+ {
if (this->bShowName_ && this->bShowScore_ && player2_ != NULL)
output2 = score2 + " - " + name2;
else if (this->bShowScore_)
@@ -151,16 +145,16 @@
output2 = name2;
}
- std::string output("PONG");
- if (this->bShowName_ || this->bShowScore_)
- {
- if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
- output = output1 + ':' + output2;
- else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
- output = output1 + output2;
- }
- this->setCaption(output);
+ std::string output("PONG");
+ if (this->bShowName_ || this->bShowScore_)
+ {
+ if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
+ output = output1 + ':' + output2;
+ else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
+ output = output1 + output2;
}
+
+ this->setCaption(output);
}
}
More information about the Orxonox-commit
mailing list