-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.cpp
89 lines (77 loc) · 2.01 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
/**
* Full program for message-board exercise.
*
* Author: Elad Vaknin
* Since : 2021-04
*/
#include <string>
#include <iostream>
#include <stdexcept>
#include <algorithm>
#include "Direction.hpp"
#include "Board.hpp"
using namespace std;
using ariel::Direction;
namespace ariel{
Board::Board(){}
//Read from the board funcion
string Board::read(unsigned int row,unsigned int colum, Direction direction,unsigned int len){
char sign='_';
string message;
for (size_t i = 0; i < len; i++)
{
if(message_board[make_pair(row,colum)] > 0){
sign=message_board[make_pair(row,colum)];
}
else{
sign='_';
}
message+=sign;
if(Direction::Horizontal==direction){
colum++;
}
else{
row++;
}
}
return message;
}
// Post funcion
void Board::post(unsigned int row,unsigned int col,Direction direction,string st){
for (size_t i = 0; i < st.length(); i++)
{
message_board[make_pair(row,col)]=st.at(i);
if(Direction::Horizontal==direction){
col++;
}
else{
row++;
}
}
cout<< "post" <<endl;
}
// Show function
void Board::show(){
unsigned int i = 0;
unsigned int col = 0;
for(auto elem : message_board){
if(i==0){
std::cout << elem.second<<endl;
i++;
col =elem.first.first;
}
else{
if(col != elem.first.first){
std::cout<<endl;
std::cout << elem.second;
col=elem.first.first;
}
else{
std::cout << elem.second;
}
}
}
cout<<endl;
cout<< "show" <<endl;
}
}