Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8428


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.

Location:
code/branches/spacerace/src/modules/gametypes
Files:
2 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
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.h

    r8250 r8428  
    3434#include "RaceCheckPoint.h"
    3535#include <boost/concept_check.hpp>
     36#include <util/Clock.h>
     37#include <string.h>
     38#include <set>
    3639
    3740namespace orxonox
    3841{
     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       
    3962    class _OrxonoxExport SpaceRace : public Gametype
    4063    {
    4164        public:
    4265            SpaceRace(BaseObject* creator);
    43             virtual ~SpaceRace(){};
     66            virtual ~SpaceRace() {}
    4467           
    4568            virtual void tick(float dt);
    4669           
    47             inline void newCheckpointReached()
    48                 { this->checkpointsReached_++; }
     70            virtual void start();
     71            virtual void end();
     72           
     73            virtual void newCheckpointReached();
     74           
    4975            inline void setCheckpointsReached(int n)
    5076                { this->checkpointsReached_ = n;}
     
    5682        private:
    5783            int checkpointsReached_;
     84            Clock *clock_;
     85            std::set<float> scores_;
     86           
    5887    };
    5988}
Note: See TracChangeset for help on using the changeset viewer.