libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


maze.h
00001 //---------------------------------------------------------------------
00002 //  Algorithmic Conjurings @ http://www.coyotegulch.com
00003 //
00004 //  maze.h (libcoyotl)
00005 //
00006 //  Maze generation and exploration tools
00007 //-----------------------------------------------------------------------
00008 //
00009 //  Copyright 1990-2005 Scott Robert Ladd
00010 //
00011 //  This program is free software; you can redistribute it and/or modify
00012 //  it under the terms of the GNU General Public License as published by
00013 //  the Free Software Foundation; either version 2 of the License, or
00014 //  (at your option) any later version.
00015 //  
00016 //  This program is distributed in the hope that it will be useful,
00017 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //  
00021 //  You should have received a copy of the GNU General Public License
00022 //  along with this program; if not, write to the
00023 //      Free Software Foundation, Inc.
00024 //      59 Temple Place - Suite 330
00025 //      Boston, MA 02111-1307, USA.
00026 //
00027 //-----------------------------------------------------------------------
00028 //
00029 //  For more information on this software package, please visit
00030 //  Scott's web site, Coyote Gulch Productions, at:
00031 //
00032 //      http://www.coyotegulch.com
00033 //  
00034 //-----------------------------------------------------------------------
00035 
00036 #if !defined(LIBCOYOTL_MAZE_H)
00037 #define LIBCOYOTL_MAZE_H
00038 
00039 #include <string>
00040 #include <iostream>
00041 #include <cstddef>
00042 
00043 namespace libcoyotl
00044 {
00046 
00055     class maze
00056     {
00057     public:
00059         enum wall
00060         {
00061             WALL_OPEN,      
00062             WALL_CLOSED,    
00063             WALL_SOLID      
00064         };
00065 
00067         enum direction
00068         {
00069             DIR_NORTH,      
00070             DIR_EAST,       
00071             DIR_SOUTH,      
00072             DIR_WEST        
00073         };
00074 
00076 
00079         struct position
00080         {
00082             size_t m_row;
00083 
00085             size_t m_col;
00086         };
00087 
00089 
00094         struct cell
00095         {
00097             wall * m_walls[4];
00098 
00100 
00104             cell();
00105 
00107 
00111             cell(const cell & a_source);
00112 
00114 
00119             cell & operator = (const cell & a_source);
00120 
00122 
00126             virtual ~cell();
00127         };
00128 
00130 
00139         class architect
00140         {
00141         public:
00143 
00148             virtual void create_floor_plan(maze & a_target) = 0;
00149 
00150         protected:
00152 
00158             static cell ** get_cells(maze & a_target)
00159             {
00160                 return a_target.m_cells;
00161             }
00162         };
00163 
00164     private:
00166         friend class architect;
00167 
00168     public:
00170 
00178         static maze generate(size_t a_width, size_t a_height, architect & a_architect);
00179 
00181 
00186         static maze load(std::istream & a_source);
00187 
00189 
00193         maze(const maze & a_source);
00194 
00196 
00200         maze & operator = (const maze & a_source);
00201 
00203 
00206         virtual ~maze();
00207 
00209 
00215         void save(std::ostream & a_receiver);
00216 
00218 
00222         size_t get_width() const
00223         {
00224             return m_width;
00225         }
00226 
00228 
00232         size_t get_height() const
00233         {
00234             return m_height;
00235         }
00236 
00238 
00242         position get_entrance_cell_position() const
00243         {
00244             return m_entrance;
00245         }
00246 
00248 
00252         position get_exit_cell_position() const
00253         {
00254             return m_exit;
00255         }
00256 
00258 
00264         cell get_cell(size_t a_col, size_t a_row) const;
00265 
00266     protected:
00268 
00275         maze(size_t a_width, size_t a_height);
00276 
00278 
00282         void construct();
00283 
00285 
00288         void release();
00289 
00291 
00295         void deep_copy(const maze & a_source);
00296 
00298 
00302         void read(std::istream & a_source);
00303 
00304     protected:
00306         size_t m_width; 
00307 
00309         size_t m_height;
00310 
00312         position m_entrance;    
00313 
00315         position m_exit;        
00316 
00318         cell ** m_cells;        
00319     };
00320 
00321 } // end namespace
00322 
00323 #endif

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.