libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


maze.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 //
4 // maze.h (libcoyotl)
5 //
6 // Maze generation and exploration tools
7 //-----------------------------------------------------------------------
8 //
9 // Copyright 1990-2005 Scott Robert Ladd
10 //
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the
23 // Free Software Foundation, Inc.
24 // 59 Temple Place - Suite 330
25 // Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------
28 //
29 // For more information on this software package, please visit
30 // Scott's web site, Coyote Gulch Productions, at:
31 //
32 // http://www.coyotegulch.com
33 //
34 //-----------------------------------------------------------------------
35 
36 #if !defined(LIBCOYOTL_MAZE_H)
37 #define LIBCOYOTL_MAZE_H
38 
39 #include <string>
40 #include <iostream>
41 #include <cstddef>
42 
43 namespace libcoyotl
44 {
46 
55  class maze
56  {
57  public:
59  enum wall
60  {
61  WALL_OPEN,
64  };
65 
67  enum direction
68  {
69  DIR_NORTH,
73  };
74 
76 
79  struct position
80  {
82  size_t m_row;
83 
85  size_t m_col;
86  };
87 
89 
94  struct cell
95  {
97  wall * m_walls[4];
98 
100 
104  cell();
105 
107 
111  cell(const cell & a_source);
112 
114 
119  cell & operator = (const cell & a_source);
120 
122 
126  virtual ~cell();
127  };
128 
130 
139  class architect
140  {
141  public:
143 
148  virtual void create_floor_plan(maze & a_target) = 0;
149 
150  protected:
152 
158  static cell ** get_cells(maze & a_target)
159  {
160  return a_target.m_cells;
161  }
162  };
163 
164  private:
166  friend class architect;
167 
168  public:
170 
178  static maze generate(size_t a_width, size_t a_height, architect & a_architect);
179 
181 
186  static maze load(std::istream & a_source);
187 
189 
193  maze(const maze & a_source);
194 
196 
200  maze & operator = (const maze & a_source);
201 
203 
206  virtual ~maze();
207 
209 
215  void save(std::ostream & a_receiver);
216 
218 
222  size_t get_width() const
223  {
224  return m_width;
225  }
226 
228 
232  size_t get_height() const
233  {
234  return m_height;
235  }
236 
238 
243  {
244  return m_entrance;
245  }
246 
248 
253  {
254  return m_exit;
255  }
256 
258 
264  cell get_cell(size_t a_col, size_t a_row) const;
265 
266  protected:
268 
275  maze(size_t a_width, size_t a_height);
276 
278 
282  void construct();
283 
285 
288  void release();
289 
291 
295  void deep_copy(const maze & a_source);
296 
298 
302  void read(std::istream & a_source);
303 
304  protected:
306  size_t m_width;
307 
309  size_t m_height;
310 
313 
316 
319  };
320 
321 } // end namespace
322 
323 #endif

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