forked from avigael-cs/messageboard-b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.cpp
68 lines (60 loc) · 1.68 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
#include "Board.hpp"
using namespace std;
namespace ariel {
void Board::post(unsigned int row, unsigned int col, Direction drct, string const &msg)
{
//Updates the board according to the message
this->maxRow = max(this->maxRow, row);
this->minRow = min(this->minRow, row);
this->maxCol = max(this->maxCol, col);
this->minCol = min(this->minCol, col);
unsigned int length = 0;
//Write the message on the board
for(char c: msg)
{
this->myBoard[row][col].entry = c;
if(drct == Direction::Horizontal){
col++;
}
else
{
row++;
}
length++;
}
if(drct == Direction::Horizontal){
maxCol+=length;
}
else
{
maxRow+=length;
}
}
std::string Board::read(unsigned int row, unsigned int col, Direction drct, unsigned int length)
{
string msg;
for(unsigned int i=0; i<length; i++){
msg += this->myBoard[row][col].entry;
if(drct == Direction::Horizontal){
col++;
}
else
{
row++;
}
}
return msg;
}
//brief Displays the board to the screen
void Board::show()
{
for (unsigned int row = this->minRow; row <= this->maxRow; row++)
{
for (unsigned int col = this->minCol; col <= this->maxCol; col++)
{
cout << this->myBoard[row][col].entry;
}
cout << endl;
}
}
}