Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/tetris/TetrisScore.cc @ 12268

Last change on this file since 12268 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
Line 
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.
32    @ingroup Tetris
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{
46    RegisterClass(TetrisScore);
47
48    /**
49    @brief
50        Constructor. Registers and initializes the object.
51    @ingroup Tetris
52    */
53    TetrisScore::TetrisScore(Context* context) : OverlayText(context)
54    {
55        RegisterObject(TetrisScore);
56
57        this->owner_ = nullptr;
58        this->player_ = nullptr;
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.
81        if (this->owner_ != nullptr)
82        {
83            std::string score("0");
84            if(!this->owner_->hasEnded())
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.
93                if (player_ != nullptr)
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.
103        Sets the owner to nullptr, if it is not a pointer to a Tetris game.
104    */
105    void TetrisScore::changedOwner()
106    {
107        SUPER(TetrisScore, changedOwner);
108
109        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
110            this->owner_ = orxonox_cast<Tetris*>(this->getOwner()->getGametype());
111        else
112            this->owner_ = nullptr;
113    }
114}
Note: See TracBrowser for help on using the repository browser.