Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2011, 3:29:57 PM (13 years ago)
Author:
msalomon
Message:

Space Race gamtype with a clock and a set to save the time of the player.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.cc

    r8250 r8428  
    3131#include "core/CoreIncludes.h"
    3232#include "network/Host.h"
     33#include <util/Clock.h>
     34#include <util/Math.h>
     35#include "util/Convert.h"
    3336
    3437namespace orxonox
     
    4043        RegisterObject(SpaceRace);
    4144        this->checkpointsReached_ = 0;
    42         this->numberOfBots_ = 0;       
     45        this->numberOfBots_ = 0;
    4346    }
    4447   
    4548    void SpaceRace::tick(float dt)
    4649    {
    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);
    4893    }
    4994
Note: See TracChangeset for help on using the changeset viewer.