996
|
1 // Board.cpp
|
|
2
|
|
3 #include "lib.h"
|
|
4 #include "Board.h"
|
|
5
|
|
6 using namespace std;
|
|
7
|
|
8 Board::Board()
|
|
9 {
|
|
10 }
|
|
11
|
|
12 Board::~Board()
|
|
13 {
|
|
14 }
|
|
15
|
|
16 Board::Board(string const & newName, list<string> const & newData)
|
|
17 {
|
|
18 reset(newName, newData);
|
|
19 }
|
|
20
|
|
21 // This scheme makes maxX and maxY one greater than they have to
|
|
22 // be. But this doesn't matter.
|
|
23 void Board::reset(string const & newName, list<string> const & newData)
|
|
24 {
|
|
25 maxX = 0;
|
|
26 maxY = 0;
|
|
27 name = newName;
|
|
28 data.clear();
|
|
29 data.reserve(newData.size());
|
|
30 list<string>::const_iterator sourcePos = newData.begin();
|
|
31 list<string>::const_iterator sourceLimit = newData.end();
|
|
32 for (; sourcePos != sourceLimit; ++sourcePos)
|
|
33 {
|
|
34 data.push_back(*sourcePos);
|
|
35 maxX = max(maxX, static_cast<int>(sourcePos->size()));
|
|
36 ++maxY;
|
|
37 }
|
|
38 }
|
|
39
|
|
40 char Board::at(Vec pos) const
|
|
41 {
|
|
42 char result = ' ';
|
|
43 if (pos.y >= 0 && pos.y < static_cast<int>(data.size()))
|
|
44 {
|
|
45 if (pos.x >= 0 && pos.x < static_cast<int>(data[pos.y].size()))
|
|
46 {
|
|
47 result = data[pos.y][pos.x];
|
|
48 }
|
|
49 }
|
|
50 return result;
|
|
51 }
|
|
52
|
|
53 string const & Board::getName(void) const
|
|
54 {
|
|
55 return name;
|
|
56 }
|
|
57
|
|
58 int Board::getMinX(void) const
|
|
59 {
|
|
60 return 0;
|
|
61 }
|
|
62
|
|
63 int Board::getMaxX(void) const
|
|
64 {
|
|
65 return maxX;
|
|
66 }
|
|
67
|
|
68 int Board::getMinY(void) const
|
|
69 {
|
|
70 return 0;
|
|
71 }
|
|
72
|
|
73 int Board::getMaxY(void) const
|
|
74 {
|
|
75 return maxY;
|
|
76 }
|