[Orxonox-commit 4420] r9091 - code/branches/pCuts/src/modules/tetris

jo at orxonox.net jo at orxonox.net
Mon Apr 16 22:42:58 CEST 2012


Author: jo
Date: 2012-04-16 22:42:57 +0200 (Mon, 16 Apr 2012)
New Revision: 9091

Added:
   code/branches/pCuts/src/modules/tetris/TetrisScore.cc
   code/branches/pCuts/src/modules/tetris/TetrisScore.h
Log:
Adding missing files.

Added: code/branches/pCuts/src/modules/tetris/TetrisScore.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisScore.cc	                        (rev 0)
+++ code/branches/pCuts/src/modules/tetris/TetrisScore.cc	2012-04-16 20:42:57 UTC (rev 9091)
@@ -0,0 +1,124 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Johannes Ritz
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file TetrisScore.cc
+    @brief Implementation of the TetrisScore class.
+*/
+
+#include "TetrisScore.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "util/Convert.h"
+
+#include "infos/PlayerInfo.h"
+
+#include "Tetris.h"
+
+namespace orxonox
+{
+    CreateFactory(TetrisScore);
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
+    TetrisScore::TetrisScore(BaseObject* creator) : OverlayText(creator)
+    {
+        RegisterObject(TetrisScore);
+
+        this->owner_ = 0;
+        this->player_ = NULL;
+        this->lock_ = true;
+    }
+
+    /**
+    @brief
+        Destructor.
+    */
+    TetrisScore::~TetrisScore()
+    {
+    }
+
+    /**
+    @brief
+        Method to create a TetrisScore through XML.
+    */
+    void TetrisScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(TetrisScore, XMLPort, xmlelement, mode);
+    }
+
+    /**
+    @brief
+        Is called each tick.
+        Creates and sets the caption to be displayed by the TetrisScore.
+    @param dt
+        The time that has elapsed since the last tick.
+    */
+    void TetrisScore::tick(float dt)
+    {
+        SUPER(TetrisScore, tick, dt);
+
+        // If the owner is set. The owner being a Tetris game.
+        if (this->owner_ != NULL)
+        {
+            std::string score("0");
+	        if(!this->owner_->hasEnded() && this->lock_)
+            {
+                //get the player
+                player_ = this->owner_->getPlayer();
+                this->lock_ = false;
+            }
+
+            if(this->owner_->hasStarted())
+            {
+                // Save the name and score of each player as a string.
+                if (player_ != NULL)
+                    score = multi_cast<std::string>(this->owner_->getScore(player_));
+            }
+            this->setCaption(score);
+        }
+    }
+
+    /**
+    @brief
+        Is called when the owner changes.
+        Sets the owner to NULL, if it is not a pointer to a Tetris game.
+    */
+    void TetrisScore::changedOwner()
+    {
+        SUPER(TetrisScore, changedOwner);
+
+        if (this->getOwner() != NULL && this->getOwner()->getGametype())
+            this->owner_ = orxonox_cast<Tetris*>(this->getOwner()->getGametype().get());
+        else
+            this->owner_ = 0;
+    }
+}

Added: code/branches/pCuts/src/modules/tetris/TetrisScore.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisScore.h	                        (rev 0)
+++ code/branches/pCuts/src/modules/tetris/TetrisScore.h	2012-04-16 20:42:57 UTC (rev 9091)
@@ -0,0 +1,72 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file TetrisScore.h
+    @brief Declaration of the TetrisScore class.
+    @ingroup Tetris
+*/
+
+#ifndef _TetrisScore_H__
+#define _TetrisScore_H__
+
+#include "tetris/TetrisPrereqs.h"
+
+#include "tools/interfaces/Tickable.h"
+
+#include "overlays/OverlayText.h"
+
+namespace orxonox
+{
+
+    /**
+    @brief
+        The TetrisScore class displays the score for a game of @ref orxonox::Tetris "Tetris".
+
+    @author
+        Johannes Ritz
+
+    @ingroup Tetris
+    */
+    class _TetrisExport TetrisScore : public OverlayText, public Tickable
+    {
+        public:
+            TetrisScore(BaseObject* creator);
+            virtual ~TetrisScore();
+
+            virtual void tick(float dt); //!< Creates and sets the caption to be displayed by the TetrisScore.
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void changedOwner(); //!< Is called when the owner changes.
+
+        private:
+            Tetris* owner_; //!< The Tetris game that owns this TetrisScore.
+            PlayerInfo* player_; //!< Store information about the player permanently.
+            bool lock_;
+    };
+}
+#endif /* _TetrisScore_H__ */




More information about the Orxonox-commit mailing list