Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/tetris/TetrisScore.cc @ 12253

Last change on this file since 12253 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[9091]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Johannes Ritz
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file TetrisScore.cc
31    @brief Implementation of the TetrisScore class.
[9092]32    @ingroup Tetris
[9091]33*/
34
35#include "TetrisScore.h"
36
37#include "core/CoreIncludes.h"
38#include "util/Convert.h"
39
40#include "infos/PlayerInfo.h"
41
42#include "Tetris.h"
43
44namespace orxonox
45{
[9667]46    RegisterClass(TetrisScore);
[9091]47
48    /**
49    @brief
50        Constructor. Registers and initializes the object.
[9092]51    @ingroup Tetris
[9091]52    */
[9667]53    TetrisScore::TetrisScore(Context* context) : OverlayText(context)
[9091]54    {
55        RegisterObject(TetrisScore);
56
[11071]57        this->owner_ = nullptr;
58        this->player_ = nullptr;
[9091]59    }
60
61    /**
62    @brief
63        Destructor.
64    */
65    TetrisScore::~TetrisScore()
66    {
67    }
68
69    /**
70    @brief
71        Is called each tick.
72        Creates and sets the caption to be displayed by the TetrisScore.
73    @param dt
74        The time that has elapsed since the last tick.
75    */
76    void TetrisScore::tick(float dt)
77    {
78        SUPER(TetrisScore, tick, dt);
79
80        // If the owner is set. The owner being a Tetris game.
[11071]81        if (this->owner_ != nullptr)
[9091]82        {
83            std::string score("0");
[9945]84            if(!this->owner_->hasEnded())
[9091]85            {
86                //get the player
87                player_ = this->owner_->getPlayer();
88            }
89
90            if(this->owner_->hasStarted())
91            {
92                // Save the name and score of each player as a string.
[11071]93                if (player_ != nullptr)
[9091]94                    score = multi_cast<std::string>(this->owner_->getScore(player_));
95            }
96            this->setCaption(score);
97        }
98    }
99
100    /**
101    @brief
102        Is called when the owner changes.
[11071]103        Sets the owner to nullptr, if it is not a pointer to a Tetris game.
[9091]104    */
105    void TetrisScore::changedOwner()
106    {
107        SUPER(TetrisScore, changedOwner);
108
[11071]109        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
[10624]110            this->owner_ = orxonox_cast<Tetris*>(this->getOwner()->getGametype());
[9091]111        else
[11071]112            this->owner_ = nullptr;
[9091]113    }
114}
Note: See TracBrowser for help on using the repository browser.