[Orxonox-commit 6378] r11035 - code/branches/presentationHS15/src/modules/hover

landauf at orxonox.net landauf at orxonox.net
Mon Jan 4 11:23:59 CET 2016


Author: landauf
Date: 2016-01-04 11:23:59 +0100 (Mon, 04 Jan 2016)
New Revision: 11035

Added:
   code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc
   code/branches/presentationHS15/src/modules/hover/MazeGenerator.h
Modified:
   code/branches/presentationHS15/src/modules/hover/CMakeLists.txt
   code/branches/presentationHS15/src/modules/hover/Hover.cc
   code/branches/presentationHS15/src/modules/hover/Hover.h
Log:
moved maze-generator-code into separate class. made all static variables private members. this fixes a number of issues when reloading the hover game.

Modified: code/branches/presentationHS15/src/modules/hover/CMakeLists.txt
===================================================================
--- code/branches/presentationHS15/src/modules/hover/CMakeLists.txt	2016-01-04 09:13:21 UTC (rev 11034)
+++ code/branches/presentationHS15/src/modules/hover/CMakeLists.txt	2016-01-04 10:23:59 UTC (rev 11035)
@@ -1,19 +1,20 @@
 SET_SOURCE_FILES(Hover_SRC_FILES
-Hover.cc
-HoverShip.cc
-HoverWall.cc
-HoverOrigin.cc
-TimeHUD.cc
-FlagHUD.cc
-HoverFlag.cc
+  Hover.cc
+  HoverShip.cc
+  HoverWall.cc
+  HoverOrigin.cc
+  HoverFlag.cc
+  TimeHUD.cc
+  FlagHUD.cc
+  MazeGenerator.cc
 )
 
 ORXONOX_ADD_LIBRARY(hover
   PLUGIN
   FIND_HEADER_FILES
   LINK_LIBRARIES
+    orxonox
     objects
-    orxonox
     overlays
   SOURCE_FILES ${Hover_SRC_FILES}
 )

Modified: code/branches/presentationHS15/src/modules/hover/Hover.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/Hover.cc	2016-01-04 09:13:21 UTC (rev 11034)
+++ code/branches/presentationHS15/src/modules/hover/Hover.cc	2016-01-04 10:23:59 UTC (rev 11035)
@@ -31,166 +31,95 @@
     @brief Implementation of the Hover class. Sets up the whole Minigame
 */
 
-//#include "orxonox/worldentities/pawns/SpaceShip.h"
 #include "Hover.h"
 
 #include "HoverWall.h"
 #include "HoverFlag.h"  
+#include "MazeGenerator.h"
 #include "core/CoreIncludes.h"
 
-#include <iostream>
-#include <string>
-#include <time.h>
-#include <stdlib.h>
-#include <memory.h>
-#include <stdint.h>
-#include <fstream>
-#include <vector>
-
 namespace orxonox
 {
-    bool firstTick = true;
-
-    //Levelcode represents the pitch: It's a 10x10 field. 
-    // 1 represents a Wall on the right side of this square
-    // 2 represents a Wall on the top of this square
-    // 3 represents 2 and 1 at the same time
-    // Note: the levelcode is generated from the Maze-Generator functions at the beginning of the game
-    int levelcode[10][10] =
-        {
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }, 
-        { 0,0,0,0,0,0,0,0,0,0 }
-        };
-
-    const int NumCells  = 10;
-    unsigned char* g_Maze = new unsigned char[ NumCells* NumCells ];
-
-    // current traversing position
-    int g_PtX;
-    int g_PtY;
-
-    // return the current index in g_Maze
-    int Hover::CellIdx()
-    {
-        return g_PtX + NumCells * g_PtY;
-    }   
-
-
-    int Hover::RandomInt()
-    {
-        return (rand() % NumCells);
-    }
-
-    int Hover::RandomInt4()
-    {
-        return (rand() % 4);
-    }
-
-
     RegisterUnloadableClass(Hover);
 
-
-
-
-
-
-
     Hover::Hover(Context* context) : Gametype(context)
     {
         
         RegisterObject(Hover);
+
+        this->origin_ = NULL;
+        this->flags_ = 1;
+        this->firstTick_ = true;
+
         this->setHUDTemplate("HoverHUD");
     }
 
-
-
     void Hover::tick(float dt)
     {
-
         SUPER(Hover, tick, dt);
 
-
-
-
-        if(firstTick)
+        if(this->firstTick_)
         {
+            this->firstTick_ = false;
 
-            std::fill( g_Maze, g_Maze + NumCells * NumCells, 0 );
-            g_PtX=0;
-            g_PtY=0;
-            GenerateMaze();
-            RenderMaze();
-            firstTick = false;
+            MazeGenerator generator;
+            generator.generateMaze();
+            generator.renderMaze();
 
+            const int NUM_CELLS = generator.getNumCells();
+            int* levelcode = generator.getLevelcode();
+
             //Outer Walls
-            for(int i = 0; i<10; i++){
+            for(int i = 0; i<NUM_CELLS; i++){
                 new HoverWall(origin_->getContext(), 0, i+1, 1);
-                new HoverWall(origin_->getContext(), 10, i+1, 1);
+                new HoverWall(origin_->getContext(), NUM_CELLS, i+1, 1);
                 new HoverWall(origin_->getContext(), i+1, 0, 2);
-                new HoverWall(origin_->getContext(), i+1, 10, 2);
+                new HoverWall(origin_->getContext(), i+1, NUM_CELLS, 2);
             }
 
             //Generate inner Walls according to levelcode
-            for(int y=0; y<10; y++){
-                for(int x=0; x<10; x++){
-                    switch(levelcode[y][x]){
-                        case 1: new HoverWall(origin_->getContext(), x+1, 10-y, 1);
+            for(int y=0; y<NUM_CELLS; y++){
+                for(int x=0; x<NUM_CELLS; x++){
+                    switch(levelcode[ y * NUM_CELLS + x ]){
+                        case 1: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
                                 break;
-                        case 3: new HoverWall(origin_->getContext(), x+1, 10-y, 1);
-                        case 2: new HoverWall(origin_->getContext(), x+1, 10-y, 0);
+                        case 3: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
+                        case 2: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 0);
                         default: break;
                     }
-
-
-                    
                 }   
             }
 
             //Generate 5 flags randomly
             for ( int i = 0; i < 5; i++ )
-                flagVector.push_back(new HoverFlag(origin_->getContext(), rand()%10, rand()%10));
+                flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%NUM_CELLS, rand()%NUM_CELLS));
 
-            Flags_ = flagVector.size();
+            flags_ = flagVector_.size();
 
         }//firsttick end
 
         // Check if ship collided with one of the flags
-        for ( unsigned int i = 0; i < flagVector.size(); i++ ){
-            if(flagVector[i]->getCollided()){
-                flagVector[i]->destroyLater();
-                flagVector.erase (flagVector.begin()+i);
+        for ( unsigned int i = 0; i < flagVector_.size(); i++ ){
+            if(flagVector_[i]->getCollided()){
+                flagVector_[i]->destroyLater();
+                flagVector_.erase (flagVector_.begin()+i);
             }
         }
-        Flags_ = flagVector.size();
-
-
-
+        flags_ = flagVector_.size();
     }
 
-     int Hover::getFlags()
+    int Hover::getFlags()
     {
-
         // Call start for the parent class.
-        return Flags_;
+        return flags_;
     }   
 
     void Hover::start()
     {
-
         // Call start for the parent class.
         Gametype::start();
-
     }
 
-
     void Hover::end()
     {
         // DON'T CALL THIS!
@@ -199,173 +128,4 @@
         // Instead startMainMenu, this won't crash.
         GSLevel::startMainMenu();
     }
-
-
-
-
-    // Some definitions for the Maze-Generator
-
-    //                   0  1  2  3  4  5  6  7  8
-    //                      U  R     D           L
-    int Heading_X[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 };
-    int Heading_Y[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 };
-    int Mask[9]      = {
-                                0,
-                                eDirection_Down | eDirection_Down << 4,
-                                eDirection_Left | eDirection_Left << 4,
-                                0,
-                                eDirection_Up | eDirection_Up << 4,
-                                0,
-                                0,
-                                0,
-                                eDirection_Right | eDirection_Right << 4
-                            };
-
-
-    /**
-    @brief
-        Checks if Direction is valid (for Maze-Generator)
-    */
-    bool Hover::IsDirValid( eDirection Dir )
-    {
-        int NewX = g_PtX + Heading_X[ Dir ];
-        int NewY = g_PtY + Heading_Y[ Dir ];
-
-        if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NumCells || NewY >= NumCells ) return false;
-
-        return !g_Maze[ NewX + NumCells * NewY ];
-    }
-
-    /**
-    @brief
-        Generates new Direction (for Maze-Generator)
-    */
-    eDirection Hover::GetDirection()
-    {
-        eDirection Dir = eDirection( 1 << RandomInt4() );
-
-        while ( true )
-        {
-            for ( int x = 0; x < 4; x++ )
-            {
-                if ( IsDirValid( Dir ) ) { return eDirection( Dir ); }
-
-                Dir = eDirection( Dir << 1 );
-
-                if ( Dir > eDirection_Left ) { Dir = eDirection_Up; }
-            }
-
-            Dir = eDirection( ( g_Maze[ CellIdx() ] & 0xf0 ) >> 4 );
-
-            // nowhere to go
-            if ( !Dir ) return eDirection_Invalid;
-
-            g_PtX += Heading_X[ Dir ];
-            g_PtY += Heading_Y[ Dir ];
-
-            Dir = eDirection( 1 << RandomInt4() );
-        }
-    }
-
-    /**
-    @brief
-        Generates a Maze (for Maze-Generator)
-    */
-    void Hover::GenerateMaze()
-    {
-
-        for ( eDirection Dir = GetDirection(); Dir != eDirection_Invalid; Dir = GetDirection() )
-        {
-            g_Maze[ CellIdx() ] |= Dir;
-
-            g_PtX += Heading_X[ Dir ];
-            g_PtY += Heading_Y[ Dir ];
-
-            g_Maze[ CellIdx() ] = Mask[ Dir ];
-        }
-    }  
-    
-    /**
-    @brief
-        Print Maze (for Debugging only)
-    */
-    void Hover::MazeOut(){
-        for ( int y = 0; y < NumCells; y++ )
-        {
-            for ( int x = 0; x < NumCells; x++ )
-            {
-                char v = g_Maze[ y * NumCells + x ];
-                orxout()<<"[";
-                if ( ( v & eDirection_Up    ) ) orxout()<<"U";
-                else orxout()<<" ";
-                if ( ( v & eDirection_Right ) ) orxout()<<"R";
-                else orxout()<<" ";
-                if ( ( v & eDirection_Down  ) ) orxout()<<" ";
-                else orxout()<<" ";
-                if ( ( v & eDirection_Left  ) ) orxout()<<" ";
-                else orxout()<<" ";
-                orxout()<<"]";
-            }
-            orxout()<<endl;
-        }
-
-    }
-
-    /**
-    @brief
-        Print Levelcode (for Debugging only)
-    */
-    void Hover::LevelOut(){
-        for ( int y = 0; y < NumCells; y++ )
-        {
-            for ( int x = 0; x < NumCells; x++ )
-            {
-                orxout()<<"[";
-                if ( levelcode[x][y] < 2) orxout()<<"U";
-                else orxout()<<" ";
-                if ( levelcode[x][y] % 2 == 0) orxout()<<"R";
-                else orxout()<<" ";
-
-                orxout()<<" ";
-                orxout()<<" ";
-                orxout()<<"]";
-            }
-            orxout()<<endl;
-        }
-    }
-
-    /**
-    @brief
-        Generate Levelcode from Maze
-    */
-    void Hover::RenderMaze()
-    {
-        for ( int y = 0; y < NumCells; y++ )
-        {
-            for ( int x = 0; x < NumCells; x++ )
-            {
-                char v = g_Maze[ y * NumCells + x ];
-
-                if ( !( v & eDirection_Up    ) && y >0) levelcode[y][x] |= 2;
-                if ( !( v & eDirection_Right ) && x <9) levelcode[y][x] |= 1;
-            }
-        }
-        for ( int y = 3; y < 7; y++ )
-        {
-            for ( int x = 3; x < 7; x++ )
-            {
-
-                if(y == 3 && x != 7)
-                    levelcode[y][x] &= 2;
-                else if (x == 7 && y != 3)
-                    levelcode[y][x] &= 1;
-                else if(x != 7)
-                    levelcode[y][x] = 0;
-            }
-        }
-
-    }
-
-
-
 }

Modified: code/branches/presentationHS15/src/modules/hover/Hover.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/Hover.h	2016-01-04 09:13:21 UTC (rev 11034)
+++ code/branches/presentationHS15/src/modules/hover/Hover.h	2016-01-04 10:23:59 UTC (rev 11035)
@@ -58,16 +58,6 @@
 
 namespace orxonox
 {
-
-    enum eDirection
-    {
-        eDirection_Invalid = 0,
-        eDirection_Up      = 1,
-        eDirection_Right   = 2,
-        eDirection_Down    = 4,
-        eDirection_Left    = 8
-    }; 
-
     class _HoverExport Hover : public Gametype
     {
        public:
@@ -79,26 +69,15 @@
             virtual void tick(float dt);          
 
             void setOrigin(HoverOrigin* origin)
-                       { this->origin_ = origin; }
+                { this->origin_ = origin; }
 
             int getFlags();
-            WeakPtr<HoverOrigin> origin_;
 
         private:
-            int CellIdx();
-            int RandomInt();
-            int RandomInt4();
-            int Flags_;
-
-            bool IsDirValid( eDirection Dir );
-            eDirection GetDirection();
-            void GenerateMaze();
-            void RenderMaze();
-            void MazeOut();
-            void LevelOut();
-            std::vector<HoverFlag*> flagVector;
-
-
+            WeakPtr<HoverOrigin> origin_;
+            std::vector<HoverFlag*> flagVector_;
+            int flags_;
+            bool firstTick_;
     };
 }
 

Copied: code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc (from rev 11026, code/branches/presentationHS15/src/modules/hover/Hover.cc)
===================================================================
--- code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc	                        (rev 0)
+++ code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc	2016-01-04 10:23:59 UTC (rev 11035)
@@ -0,0 +1,240 @@
+/*
+ *   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:
+ *      Manuel Meier
+ *   Co-authors:
+ *      Cyrill Muskelprotz
+ *
+ */
+
+/**
+    @file MazeGenerator.cc
+    @brief Implementation of the MazeGenerator class. Generates the maze.
+*/
+
+#include "MazeGenerator.h"
+
+#include <vector>
+
+#include "util/Output.h"
+#include "util/Math.h"
+
+namespace orxonox
+{
+    MazeGenerator::MazeGenerator()
+    {
+        //levelcode_ represents the pitch: It's a 10x10 field.
+        // 1 represents a Wall on the right side of this square
+        // 2 represents a Wall on the top of this square
+        // 3 represents 2 and 1 at the same time
+        // Note: the levelcode_ is generated from the Maze-Generator functions at the beginning of the game
+        this->levelcode_ = new int[ NUM_CELLS*NUM_CELLS ];;
+        std::fill( levelcode_, levelcode_ + NUM_CELLS*NUM_CELLS, 0 );
+
+        this->maze_ = new unsigned char[ NUM_CELLS*NUM_CELLS ];
+        std::fill( maze_, maze_ + NUM_CELLS*NUM_CELLS, 0 );
+
+        // current traversing position
+        this->ptX_ = 0;
+        this->ptY_ = 0;
+
+        //                  0  1  2  3  4  5  6  7  8
+        //                     U  R     D           L
+        int headingX[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 };
+        int headingY[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 };
+        int mask[9]     = {
+                              0,
+                              eDirection_Down | eDirection_Down << 4,
+                              eDirection_Left | eDirection_Left << 4,
+                              0,
+                              eDirection_Up | eDirection_Up << 4,
+                              0,
+                              0,
+                              0,
+                              eDirection_Right | eDirection_Right << 4
+                          };
+
+        std::copy(headingX, headingX + 9, this->headingX_);
+        std::copy(headingY, headingY + 9, this->headingY_);
+        std::copy(mask,     mask + 9,     this->mask_);
+    }
+
+    /**
+    @brief
+        Checks if Direction is valid (for Maze-Generator)
+    */
+    bool MazeGenerator::isDirValid( eDirection Dir )
+    {
+        int NewX = ptX_ + headingX_[ Dir ];
+        int NewY = ptY_ + headingY_[ Dir ];
+
+        if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NUM_CELLS || NewY >= NUM_CELLS ) return false;
+
+        return !maze_[ NewX + NUM_CELLS * NewY ];
+    }
+
+    /**
+    @brief
+        Generates new Direction (for Maze-Generator)
+    */
+    eDirection MazeGenerator::getDirection()
+    {
+        eDirection Dir = eDirection( 1 << randomInt4() );
+
+        while ( true )
+        {
+            for ( int x = 0; x < 4; x++ )
+            {
+                if ( isDirValid( Dir ) ) { return eDirection( Dir ); }
+
+                Dir = eDirection( Dir << 1 );
+
+                if ( Dir > eDirection_Left ) { Dir = eDirection_Up; }
+            }
+
+            Dir = eDirection( ( maze_[ cellIdx() ] & 0xf0 ) >> 4 );
+
+            // nowhere to go
+            if ( !Dir ) return eDirection_Invalid;
+
+            ptX_ += headingX_[ Dir ];
+            ptY_ += headingY_[ Dir ];
+
+            Dir = eDirection( 1 << randomInt4() );
+        }
+    }
+
+    /**
+    @brief
+        Generates a Maze (for Maze-Generator)
+    */
+    void MazeGenerator::generateMaze()
+    {
+
+        for ( eDirection Dir = getDirection(); Dir != eDirection_Invalid; Dir = getDirection() )
+        {
+            maze_[ cellIdx() ] |= Dir;
+
+            ptX_ += headingX_[ Dir ];
+            ptY_ += headingY_[ Dir ];
+
+            maze_[ cellIdx() ] = mask_[ Dir ];
+        }
+    }  
+    
+    /**
+    @brief
+        Print Maze (for Debugging only)
+    */
+    void MazeGenerator::mazeOut(){
+        for ( int y = 0; y < NUM_CELLS; y++ )
+        {
+            for ( int x = 0; x < NUM_CELLS; x++ )
+            {
+                char v = maze_[ y * NUM_CELLS + x ];
+                orxout()<<"[";
+                if ( ( v & eDirection_Up    ) ) orxout()<<"U";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Right ) ) orxout()<<"R";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Down  ) ) orxout()<<" ";
+                else orxout()<<" ";
+                if ( ( v & eDirection_Left  ) ) orxout()<<" ";
+                else orxout()<<" ";
+                orxout()<<"]";
+            }
+            orxout()<<endl;
+        }
+
+    }
+
+    /**
+    @brief
+        Print levelcode_ (for Debugging only)
+    */
+    void MazeGenerator::levelOut(){
+        for ( int y = 0; y < NUM_CELLS; y++ )
+        {
+            for ( int x = 0; x < NUM_CELLS; x++ )
+            {
+                orxout()<<"[";
+                if ( levelcode_[ y * NUM_CELLS + x ] < 2) orxout()<<"U";
+                else orxout()<<" ";
+                if ( levelcode_[ y * NUM_CELLS + x ] % 2 == 0) orxout()<<"R";
+                else orxout()<<" ";
+
+                orxout()<<" ";
+                orxout()<<" ";
+                orxout()<<"]";
+            }
+            orxout()<<endl;
+        }
+    }
+
+    /**
+    @brief
+        Generate levelcode_ from Maze
+    */
+    void MazeGenerator::renderMaze()
+    {
+        for ( int y = 0; y < NUM_CELLS; y++ )
+        {
+            for ( int x = 0; x < NUM_CELLS; x++ )
+            {
+                char v = maze_[ y * NUM_CELLS + x ];
+
+                if ( !( v & eDirection_Up    ) && y >0) levelcode_[ y * NUM_CELLS + x ] |= 2;
+                if ( !( v & eDirection_Right ) && x <9) levelcode_[ y * NUM_CELLS + x ] |= 1;
+            }
+        }
+        for ( int y = 3; y < 7; y++ )
+        {
+            for ( int x = 3; x < 7; x++ )
+            {
+
+                if(y == 3 && x != 7)
+                    levelcode_[ y * NUM_CELLS + x ] &= 2;
+                else if (x == 7 && y != 3)
+                    levelcode_[ y * NUM_CELLS + x ] &= 1;
+                else if(x != 7)
+                    levelcode_[ y * NUM_CELLS + x ] = 0;
+            }
+        }
+
+    }
+
+    // return the current index in maze_
+    int MazeGenerator::cellIdx()
+    {
+        return ptX_ + NUM_CELLS * ptY_;
+    }
+
+    int MazeGenerator::randomInt()
+    {
+        return (rand() % NUM_CELLS);
+    }
+
+    int MazeGenerator::randomInt4()
+    {
+        return (rand() % 4);
+    }
+}

Copied: code/branches/presentationHS15/src/modules/hover/MazeGenerator.h (from rev 11026, code/branches/presentationHS15/src/modules/hover/Hover.h)
===================================================================
--- code/branches/presentationHS15/src/modules/hover/MazeGenerator.h	                        (rev 0)
+++ code/branches/presentationHS15/src/modules/hover/MazeGenerator.h	2016-01-04 10:23:59 UTC (rev 11035)
@@ -0,0 +1,87 @@
+/*
+ *   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.
+ *
+ *   Master of Desaster:
+ *      Manuel Meier
+ *   Co-authors:
+ *      Cyrill Muskelprotz
+ *
+ */
+
+/**
+    @file MazeGenerator.h
+    @ingroup Hover
+*/
+
+#ifndef _MazeGenerator_H__
+#define _MazeGenerator_H__
+
+#include "HoverPrereqs.h"
+
+namespace orxonox
+{
+    enum eDirection
+    {
+        eDirection_Invalid = 0,
+        eDirection_Up      = 1,
+        eDirection_Right   = 2,
+        eDirection_Down    = 4,
+        eDirection_Left    = 8
+    }; 
+
+    class _HoverExport MazeGenerator
+    {
+        public:
+            MazeGenerator();
+
+            void generateMaze();
+            void renderMaze();
+            void mazeOut();
+            void levelOut();
+
+            int* getLevelcode() const
+                { return this->levelcode_; }
+            int getNumCells() const
+                { return NUM_CELLS; }
+
+        private:
+            bool isDirValid( eDirection Dir );
+            eDirection getDirection();
+
+            int cellIdx();
+            int randomInt();
+            int randomInt4();
+
+            static const int NUM_CELLS = 10;
+            int* levelcode_;
+            unsigned char* maze_;
+
+            // current traversing position
+            int ptX_;
+            int ptY_;
+
+            int headingX_[9];
+            int headingY_[9];
+            int mask_[9];
+    };
+}
+
+#endif /* _MazeGenerator_H__ */




More information about the Orxonox-commit mailing list