Logo
~Sockets~
~Examples~
~Contact~


World.cpp

Go to the documentation of this file.
00001 //World.cpp
00002 /*
00003 Copyright (C) 2004  Anders Hedstrom
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 //#include <stdio.h>
00021 
00022 #include "SmallHandler.h"
00023 #include "World.h"
00024 
00025 
00026 
00027 
00028 World::World(SmallHandler& h) : m_handler(h)
00029 {
00030         CELL *p = new CELL(1000,1000,"The Beginning");
00031         m_cells.push_back(p);
00032 }
00033 
00034 
00035 World::~World()
00036 {
00037         for (cell_v::iterator it = m_cells.begin(); it != m_cells.end(); it++)
00038         {
00039                 CELL *p = *it;
00040                 delete p;
00041         }
00042 }
00043 
00044 
00045 bool World::FindAt(int x,int y,std::string& str)
00046 {
00047         for (cell_v::iterator it = m_cells.begin(); it != m_cells.end(); it++)
00048         {
00049                 CELL *p = *it;
00050                 if (p -> m_x == x && p -> m_y == y)
00051                 {
00052                         str = p -> m_name;
00053                         return true;
00054                 }
00055         }
00056         return false;
00057 }
00058 
00059 
00060 void World::GetRandomLocation(int& x,int& y,std::string& name)
00061 {
00062         int i = random() % m_cells.size();
00063         CELL *p = m_cells[i];
00064         x = p -> m_x;
00065         y = p -> m_y;
00066         name = p -> m_name;
00067 }
00068 
00069 
00070 void World::AddAt(int x,int y,const std::string& name)
00071 {
00072         CELL *p = new CELL(x,y,name);
00073         m_cells.push_back(p);
00074 }
00075 
00076 
00077 bool World::GetAt(int x,int y,std::string& str,bool& n,bool& s,bool& e,bool& w)
00078 {
00079         for (cell_v::iterator it = m_cells.begin(); it != m_cells.end(); it++)
00080         {
00081                 CELL *p = *it;
00082                 if (p -> m_x == x && p -> m_y == y)
00083                 {
00084                         str = p -> m_name;
00085                         n = p -> m_n;
00086                         s = p -> m_s;
00087                         e = p -> m_e;
00088                         w = p -> m_w;
00089                         return true;
00090                 }
00091         }
00092         return false;
00093 }
00094 
00095 
00096 void World::Open(int x,int y,const std::string& dir)
00097 {
00098         for (cell_v::iterator it = m_cells.begin(); it != m_cells.end(); it++)
00099         {
00100                 CELL *p = *it;
00101                 if (p -> m_x == x && p -> m_y == y)
00102                 {
00103                         if (dir == "north")
00104                                 p -> m_n = true;
00105                         else
00106                         if (dir == "south")
00107                                 p -> m_s = true;
00108                         else
00109                         if (dir == "east")
00110                                 p -> m_e = true;
00111                         else
00112                         if (dir == "west")
00113                                 p -> m_w = true;
00114                         break;
00115                 }
00116         }
00117 }
00118 
00119 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4