-
Notifications
You must be signed in to change notification settings - Fork 1
/
Board.cpp
81 lines (74 loc) · 2.54 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
#include <string>
#include <iostream>
#include <stdexcept>
#include <algorithm>
#include "Direction.hpp"
#include "Board.hpp"
using ariel::Direction;
using namespace std;
namespace ariel{
Board::Board(){}
//The reading function
string Board::read(unsigned int row,unsigned int colum, Direction direction,unsigned int len){
string msg; //A variable that keeps the string
char sign='_';
//A loop that passes over the position we were given and reads the word
for (size_t i = 0; i < len; i++)
{
if(msg_board[make_pair(row,colum)] > 0){ //Check that the signal in the ad according to the coordinate is correct
sign=msg_board[make_pair(row,colum)];
}
else{
sign='_'; //A place without a signal
}
msg+=sign;
if(Direction::Horizontal==direction){ //Check the direction you need to go
colum++;
}
else{
row++;
}
}
return msg;
}
//A function that infects the ad
void Board::post(unsigned int row,unsigned int colum,Direction direction,string st){
for (size_t i = 0; i < st.length(); i++)
{
msg_board[make_pair(row,colum)]=st.at(i); //Reaching the coordinate you want and pasting the signal
//Check the direction you need to go
if(Direction::Horizontal==direction){
colum++;
}
else{
row++;
}
}
cout<< "post" <<endl;
}
//Function for displaying the board
void Board::show(){
unsigned int col=0;
unsigned int i=0;
for(auto elem : msg_board){ // An iterator that goes over the locations of the board
// First condition for passing on the first element
if(i==0){
std::cout << elem.second<<endl;
i++;
col=elem.first.first; // Save the previous position (vertical) to know when to go down a line
}
else{
if(col != elem.first.first){ //If we are not in the same line we should go down a line and then print
std::cout<<endl;
std::cout << elem.second;
col=elem.first.first;
}
else{
std::cout << elem.second; //Just printing
}
}
}
cout<<endl;
cout<< "show" <<endl;
}
}