Changeset 8428
- Timestamp:
- May 9, 2011, 3:29:57 PM (14 years ago)
- Location:
- code/branches/spacerace/src/modules/gametypes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
r8250 r8428 31 31 #include "core/CoreIncludes.h" 32 32 #include "network/Host.h" 33 #include <util/Clock.h> 34 #include <util/Math.h> 35 #include "util/Convert.h" 33 36 34 37 namespace orxonox … … 40 43 RegisterObject(SpaceRace); 41 44 this->checkpointsReached_ = 0; 42 this->numberOfBots_ = 0; 45 this->numberOfBots_ = 0; 43 46 } 44 47 45 48 void SpaceRace::tick(float dt) 46 49 { 47 orxonox::Gametype::tick(dt); 50 Gametype::tick(dt); 51 } 52 53 void SpaceRace::end() 54 { 55 Gametype::end(); 56 this->clock_->capture(); 57 int s = this->clock_->getSeconds(); 58 int ms = this->clock_->getMilliseconds()-1000*s; 59 const std::string& message = "You have reached the last check point after "+ multi_cast<std::string>(s) + 60 "." + multi_cast<std::string>(ms) + " seconds."; 61 COUT(0) << message << std::endl; 62 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 63 Host::Broadcast(message); 64 float time = this->clock_->getSecondsPrecise(); 65 this->scores_.insert(time); 66 std::set<float>::iterator it; 67 for (it=this->scores_.begin(); it!=this->scores_.end(); it++) 68 COUT(0) << multi_cast<std::string>(*it) << std::endl; 69 } 70 71 void SpaceRace::start() 72 { 73 Gametype::start(); 74 75 clock_= new Clock(); 76 std::string message("The match has started! Reach the check points as quick as possible!"); 77 COUT(0) << message << std::endl; 78 Host::Broadcast(message); 79 } 80 81 void SpaceRace::newCheckpointReached() 82 { 83 this->checkpointsReached_++; 84 this->clock_->capture(); 85 int s = this->clock_->getSeconds(); 86 int ms = this->clock_->getMilliseconds()-1000*s; 87 const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 88 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 89 + " seconds."; 90 COUT(0) << message << std::endl; 91 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 92 Host::Broadcast(message); 48 93 } 49 94 -
code/branches/spacerace/src/modules/gametypes/SpaceRace.h
r8250 r8428 34 34 #include "RaceCheckPoint.h" 35 35 #include <boost/concept_check.hpp> 36 #include <util/Clock.h> 37 #include <string.h> 38 #include <set> 36 39 37 40 namespace orxonox 38 41 { 42 /* class PlayerScore { 43 public: 44 PlayerScore() { 45 this->name = ""; 46 this->time =0; 47 } 48 PlayerScore(std::string name, float time) { 49 this->name_ = name; 50 this->time_ = time; 51 } 52 PlayerScore(float time) { 53 this->name_ = "Player"; 54 this->time_ = time; 55 } 56 57 private: 58 std::string name_; 59 float time_; 60 };*/ 61 39 62 class _OrxonoxExport SpaceRace : public Gametype 40 63 { 41 64 public: 42 65 SpaceRace(BaseObject* creator); 43 virtual ~SpaceRace() {};66 virtual ~SpaceRace() {} 44 67 45 68 virtual void tick(float dt); 46 69 47 inline void newCheckpointReached() 48 { this->checkpointsReached_++; } 70 virtual void start(); 71 virtual void end(); 72 73 virtual void newCheckpointReached(); 74 49 75 inline void setCheckpointsReached(int n) 50 76 { this->checkpointsReached_ = n;} … … 56 82 private: 57 83 int checkpointsReached_; 84 Clock *clock_; 85 std::set<float> scores_; 86 58 87 }; 59 88 }
Note: See TracChangeset
for help on using the changeset viewer.