-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.cpp
93 lines (80 loc) · 1.48 KB
/
board.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "board.h"
#include <fstream>
#include "wall.h"
#include "barbwire.h"
#include "mud.h"
Board::Board(std::string _file)
{
this->loadBoard(_file);
}
Board::~Board()
{
for(size_t i=0;i<obstacles.size();i++)
{
delete getObstacle(i);
}
obstacles.clear();
}
Mobile *Board::getMobile(int c)
{
return mobiles.at(c);
}
Obstacle* Board::getObstacle(int o)
{
return obstacles.at(o);
}
bool Board::loadBoard(std::string _pathBoard)
{
std::fstream source;
source.open(_pathBoard,std::ios::in);
if ( !source.is_open() )
{
return false;
}
int numOfObs,tmp,posX,posY;
source >> Width;
source >> Height;
source >> numOfObs;
for(int i=0;i<numOfObs;i++)
{
Obstacle* obs;
source >> tmp;
source >> posX;
source >> posY;
if(tmp==wall)
{
obs = new Wall(posX,posY);
}
if(tmp==mud)
{
obs = new Mud(posX,posY);
}
if(tmp==barbwire)
{
obs = new Barbwire(posX,posY);
}
obstacles.push_back(obs);
}
source.close();
return true;
}
void Board::addMobile(Mobile *_mobile)
{
mobiles.push_back(_mobile);
}
int Board::getNumberOfObstacle()
{
return (int)obstacles.size();
}
int Board::getNumberOfMobiles()
{
return (int)mobiles.size();
}
void Board::clearMobiles()
{
mobiles.clear();
}
void Board::removeMobile(int i)
{
mobiles.erase(mobiles.begin()+i);
}