- Timestamp:
- May 27, 2011, 11:01:24 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
r8624 r8630 41 41 SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator) 42 42 { 43 RegisterObject(SpaceRace); 44 this->bCheckpointsReached_ = 0; 45 this->bTimeIsUp_ = false; 46 this->numberOfBots_ = 0; 47 } 48 49 void SpaceRace::tick(float dt) 50 { 51 Gametype::tick(dt); 43 RegisterObject(SpaceRace); 44 this->bCheckpointsReached_ = 0; 45 this->bTimeIsUp_ = false; 46 this->numberOfBots_ = 0; 52 47 } 53 48 54 49 void SpaceRace::end() 55 50 { 56 Gametype::end(); 57 if (this->bTimeIsUp_) { 58 this->clock_->capture(); 59 int s = this->clock_->getSeconds(); 60 int ms = this->clock_->getMilliseconds()-1000*s; 61 const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" 62 + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1) 63 + " before the time limit. You lose!\n"; 64 COUT(0) << message; 65 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 66 Host::Broadcast(message); 67 } 68 else { 69 this->clock_->capture(); 70 int s = this->clock_->getSeconds(); 71 int ms = this->clock_->getMilliseconds()-1000*s; 72 const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) 73 + "." + multi_cast<std::string>(ms) + " seconds.\n"; 74 COUT(0) << message << std::endl; 75 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 76 Host::Broadcast(message); 77 float time = this->clock_->getSecondsPrecise(); 78 this->scores_.insert(time); 79 std::set<float>::iterator it; 80 for (it=this->scores_.begin(); it!=this->scores_.end(); it++) 81 COUT(0) << multi_cast<std::string>(*it) << std::endl; 82 } 51 this->Gametype::end(); 52 53 if (this->bTimeIsUp_) 54 { 55 this->clock_.capture(); 56 int s = this->clock_.getSeconds(); 57 int ms = this->clock_.getMilliseconds()-1000*s; 58 const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" 59 + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1) 60 + " before the time limit. You lose!"; 61 COUT(3) << message; 62 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 63 Host::Broadcast(message); 64 } 65 else 66 { 67 this->clock_.capture(); 68 int s = this->clock_.getSeconds(); 69 int ms = this->clock_.getMilliseconds()-1000*s; 70 const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) 71 + "." + multi_cast<std::string>(ms) + " seconds."; 72 COUT(3) << message << std::endl; 73 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 74 Host::Broadcast(message); 75 float time = this->clock_.getSecondsPrecise(); 76 this->scores_.insert(time); 77 std::set<float>::iterator it; 78 for (it=this->scores_.begin(); it!=this->scores_.end(); it++) 79 COUT(3) << multi_cast<std::string>(*it) << std::endl; 80 } 83 81 } 84 82 85 83 void SpaceRace::start() 86 84 { 87 Gametype::start(); 88 89 clock_= new Clock(); 90 std::string message("The match has started! Reach the check points as quickly as possible!"); 91 COUT(0) << message << std::endl; 85 Gametype::start(); 86 87 std::string message("The match has started! Reach the check points as quickly as possible!"); 88 COUT(3) << message << std::endl; 92 89 Host::Broadcast(message); 93 90 } … … 95 92 void SpaceRace::newCheckpointReached() 96 93 { 97 98 this->clock_->capture();99 int s = this->clock_->getSeconds();100 int ms = this->clock_->getMilliseconds()-1000*s;101 const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 102 103 104 COUT(0) << message << std::endl;105 106 94 this->bCheckpointsReached_++; 95 this->clock_.capture(); 96 int s = this->clock_.getSeconds(); 97 int ms = this->clock_.getMilliseconds()-1000*s; 98 const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 99 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 100 + " seconds.\n"; 101 COUT(3) << message; 102 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 103 Host::Broadcast(message); 107 104 } 108 105
Note: See TracChangeset
for help on using the changeset viewer.