00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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