[Orxonox-commit 3748] r8428 - code/branches/spacerace/src/modules/gametypes

msalomon at orxonox.net msalomon at orxonox.net
Mon May 9 15:29:57 CEST 2011


Author: msalomon
Date: 2011-05-09 15:29:57 +0200 (Mon, 09 May 2011)
New Revision: 8428

Modified:
   code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
   code/branches/spacerace/src/modules/gametypes/SpaceRace.h
Log:
Space Race gamtype with a clock and a set to save the time of the player.


Modified: code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/branches/spacerace/src/modules/gametypes/SpaceRace.cc	2011-05-09 13:19:22 UTC (rev 8427)
+++ code/branches/spacerace/src/modules/gametypes/SpaceRace.cc	2011-05-09 13:29:57 UTC (rev 8428)
@@ -30,6 +30,9 @@
 
 #include "core/CoreIncludes.h"
 #include "network/Host.h"
+#include <util/Clock.h>
+#include <util/Math.h>
+#include "util/Convert.h"
 
 namespace orxonox
 {
@@ -39,12 +42,54 @@
     {
 	RegisterObject(SpaceRace);
 	this->checkpointsReached_ = 0;
-	this->numberOfBots_ = 0;	
+	this->numberOfBots_ = 0;
     }
     
     void SpaceRace::tick(float dt)
     {
-	orxonox::Gametype::tick(dt);
+	Gametype::tick(dt);
     }
+    
+    void SpaceRace::end()
+    {
+	Gametype::end();
+	this->clock_->capture();
+	int s = this->clock_->getSeconds();
+	int ms = this->clock_->getMilliseconds()-1000*s;
+	const std::string& message = "You have reached the last check point after "+ multi_cast<std::string>(s) +
+				      "." + multi_cast<std::string>(ms) + " seconds.";
+        COUT(0) << message << std::endl;
+	const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+        Host::Broadcast(message);
+	float time = this->clock_->getSecondsPrecise();
+	this->scores_.insert(time);
+	std::set<float>::iterator it;
+	for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
+	    COUT(0) <<  multi_cast<std::string>(*it) << std::endl;
+    }
 
+    void SpaceRace::start()
+    {
+	Gametype::start();
+	
+	clock_= new Clock();
+	std::string message("The match has started! Reach the check points as quick as possible!");
+        COUT(0) << message << std::endl;
+        Host::Broadcast(message);
+    }
+    
+    void SpaceRace::newCheckpointReached()
+    {
+      	this->checkpointsReached_++;
+	this->clock_->capture();
+	int s = this->clock_->getSeconds();
+	int ms = this->clock_->getMilliseconds()-1000*s;
+	const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 
+				      + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
+				      + " seconds.";
+	COUT(0) << message << std::endl;
+	const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+	Host::Broadcast(message);
+    }
+
 }
\ No newline at end of file

Modified: code/branches/spacerace/src/modules/gametypes/SpaceRace.h
===================================================================
--- code/branches/spacerace/src/modules/gametypes/SpaceRace.h	2011-05-09 13:19:22 UTC (rev 8427)
+++ code/branches/spacerace/src/modules/gametypes/SpaceRace.h	2011-05-09 13:29:57 UTC (rev 8428)
@@ -33,19 +33,45 @@
 #include "gametypes/GametypesPrereqs.h"
 #include "RaceCheckPoint.h"
 #include <boost/concept_check.hpp>
+#include <util/Clock.h>
+#include <string.h>
+#include <set>
 
 namespace orxonox
 {
+/*    class PlayerScore {
+	public:
+	    PlayerScore() {
+		this->name = "";
+		this->time =0;
+	    }
+	    PlayerScore(std::string name, float time) {
+		this->name_ = name;
+		this->time_ = time;
+	    }
+	    PlayerScore(float time) {
+		this->name_ = "Player";
+		this->time_ = time;
+	    }
+	
+	private:
+	    std::string name_;
+	    float time_;
+    };*/
+	
     class _OrxonoxExport SpaceRace : public Gametype
     {
 	public:
 	    SpaceRace(BaseObject* creator);
-	    virtual ~SpaceRace(){};
+	    virtual ~SpaceRace() {}
 	    
 	    virtual void tick(float dt);
 	    
-	    inline void newCheckpointReached()
-		{ this->checkpointsReached_++; }
+	    virtual void start();
+            virtual void end();
+	    
+	    virtual void newCheckpointReached();
+	    
 	    inline void setCheckpointsReached(int n)
 		{ this->checkpointsReached_ = n;}
 	    inline int getCheckpointsReached()
@@ -55,6 +81,9 @@
 	    
 	private:
 	    int checkpointsReached_;
+	    Clock *clock_;
+	    std::set<float> scores_;
+	    
     };
 }
 




More information about the Orxonox-commit mailing list