[Orxonox-commit 4229] r8900 - code/branches/gamecontent/src/modules/pong
jo at orxonox.net
jo at orxonox.net
Wed Oct 19 23:02:56 CEST 2011
Author: jo
Date: 2011-10-19 23:02:56 +0200 (Wed, 19 Oct 2011)
New Revision: 8900
Modified:
code/branches/gamecontent/src/modules/pong/Pong.cc
code/branches/gamecontent/src/modules/pong/Pong.h
code/branches/gamecontent/src/modules/pong/PongScore.cc
code/branches/gamecontent/src/modules/pong/PongScore.h
Log:
Finished Polishing Pong. (gametype ends properly now, points necessary to win are configurable)
Modified: code/branches/gamecontent/src/modules/pong/Pong.cc
===================================================================
--- code/branches/gamecontent/src/modules/pong/Pong.cc 2011-10-19 14:23:22 UTC (rev 8899)
+++ code/branches/gamecontent/src/modules/pong/Pong.cc 2011-10-19 21:02:56 UTC (rev 8900)
@@ -36,6 +36,7 @@
#include "core/CoreIncludes.h"
#include "core/EventIncludes.h"
#include "core/command/Executor.h"
+#include "core/ConfigValueIncludes.h"
#include "gamestates/GSLevel.h"
#include "chat/ChatManager.h"
@@ -74,7 +75,8 @@
// Set the type of Bots for this particular Gametype.
this->botclass_ = Class(PongBot);
- this->scoreLimit_ = 3; //TODO: 21
+ this->scoreLimit_ = 10;
+ this->setConfigValues();
}
/**
@@ -290,6 +292,7 @@
std::string name1=player1->getName();
std::string message(name1 + " has won!");
ChatManager::message(message);
+this->tick(0);
this->end();
}
else if(this->getScore(player2) >= scoreLimit_)
@@ -297,6 +300,7 @@
std::string name2=player2->getName();
std::string message2(name2 + " has won!");
ChatManager::message(message2);
+this->tick(0);
this->end();
}
// Restart the timer to start the ball.
@@ -341,4 +345,13 @@
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/gamecontent/src/modules/pong/Pong.h
===================================================================
--- code/branches/gamecontent/src/modules/pong/Pong.h 2011-10-19 14:23:22 UTC (rev 8899)
+++ code/branches/gamecontent/src/modules/pong/Pong.h 2011-10-19 21:02:56 UTC (rev 8900)
@@ -80,8 +80,9 @@
*/
void setCenterpoint(PongCenterpoint* center)
{ this->center_ = center; }
-
- PlayerInfo* getLeftPlayer() const; //!< Get the left player.
+ void setConfigValues(); //!< Makes scoreLimit configurable.
+
+ PlayerInfo* getLeftPlayer() const; //!< Get the left player.
PlayerInfo* getRightPlayer() const; //!< Get the right player.
protected:
Modified: code/branches/gamecontent/src/modules/pong/PongScore.cc
===================================================================
--- code/branches/gamecontent/src/modules/pong/PongScore.cc 2011-10-19 14:23:22 UTC (rev 8899)
+++ code/branches/gamecontent/src/modules/pong/PongScore.cc 2011-10-19 21:02:56 UTC (rev 8900)
@@ -59,6 +59,8 @@
this->bShowScore_ = false;
this->bShowLeftPlayer_ = false;
this->bShowRightPlayer_ = false;
+ this->player1_ = NULL;
+ this->player2_ = NULL;
}
/**
@@ -97,44 +99,51 @@
// If the owner is set. The owner being a Pong game.
if (this->owner_ != NULL)
{
- // Get the two players.
- PlayerInfo* player1 = this->owner_->getLeftPlayer();
- PlayerInfo* player2 = this->owner_->getRightPlayer();
-
- std::string name1;
- std::string name2;
-
- std::string score1("0");
- std::string score2("0");
-
- // Save the name and score of each player as a string.
- if (player1 != NULL)
+ if(!this->owner_->hasEnded())
{
- name1 = player1->getName();
- score1 = multi_cast<std::string>(this->owner_->getScore(player1));
+ //get the two players
+ player1_ = this->owner_->getLeftPlayer();
+ player2_ = this->owner_->getRightPlayer();
}
- 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->owner_->hasStarted())
{
- if (this->bShowName_ && this->bShowScore_ && player1 != NULL)
- output1 = name1 + " - " + score1;
- else if (this->bShowScore_)
- output1 = score1;
- else if (this->bShowName_)
- output1 = name1;
- }
+ // Get the two players.
- std::string output2;
- if (this->bShowRightPlayer_)
- {
- if (this->bShowName_ && this->bShowScore_ && player2 != NULL)
+ std::string name1;
+ std::string name2;
+
+ 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_));
+ }
+
+ // 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_)
+ {
+ if (this->bShowName_ && this->bShowScore_ && player2_ != NULL)
output2 = score2 + " - " + name2;
else if (this->bShowScore_)
output2 = score2;
@@ -142,16 +151,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;
+ 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);
}
-
- this->setCaption(output);
}
}
Modified: code/branches/gamecontent/src/modules/pong/PongScore.h
===================================================================
--- code/branches/gamecontent/src/modules/pong/PongScore.h 2011-10-19 14:23:22 UTC (rev 8899)
+++ code/branches/gamecontent/src/modules/pong/PongScore.h 2011-10-19 21:02:56 UTC (rev 8900)
@@ -121,6 +121,8 @@
bool bShowScore_; //!< Whether the score of the players is shown.
bool bShowLeftPlayer_; //!< Whether the left player is shown.
bool bShowRightPlayer_; //!< Whether the right player is shown.
+ PlayerInfo* player1_; //!< Store information about left player permanently.
+ PlayerInfo* player2_; //!< Same for the right player. To end the game properly.
};
}
#endif /* _PongScore_H__ */
More information about the Orxonox-commit
mailing list