-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextdisplay.cc
126 lines (114 loc) · 2.82 KB
/
textdisplay.cc
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "textdisplay.h"
using namespace std;
TextDisplay::TextDisplay(Board * game): game{game} {
ifstream board_text("board.txt");
string line;
while (getline(board_text, line)){
vector<char> row;
int string_size = line.length();
for (int i=0; i<string_size; i++){
row.push_back(line[i]);
}
board.push_back(row);
}
}
void TextDisplay::notify(shared_ptr<Subject> whoNotified){
string square_name = whoNotified->getName();
int squareCount=game->getSquares().size();
shared_ptr<Square> square = nullptr;
for (int i=0; i<squareCount; i++){
if (game->getSquares()[i]->getName()==square_name){
square = game->getSquares()[i];
break;
}
}
int pos=square->getPosition();
if (pos<=10){
updateSquare(square, 10, 10-pos);
}
else if(pos<=20){
updateSquare(square,20-pos,0);
}
else if(pos<=30){
updateSquare(square,0,pos-20);
}
else{
updateSquare(square, pos-30, 10);
}
}
void TextDisplay::notify(){}
void TextDisplay::updateSquare(shared_ptr<Square> square, int rown, int coln){
int row = (rown*6)+1;
int col = (coln*9);
if (square->getOwner()!=nullptr){
board[row+3][col+1]=O;
board[row+3][col+2]=COLON;
board[row+3][col+3]=square->getOwner()->getPiece();
}
else{
board[row+3][col+1]=SPACE;
board[row+3][col+2]=SPACE;
board[row+3][col+3]=SPACE;
}
board[row+3][col+4]=32;
if (square->getImprovementLevel()>0){
if (square->getImprovementLevel()==1){
board[row+3][col+5]=I;
board[row+3][col+6]=SPACE;
board[row+3][col+7]=SPACE;
}
else if (square->getImprovementLevel()==2){
board[row+3][col+5]=I;
board[row+3][col+6]=I;
board[row+3][col+7]=SPACE;
}
else if (square->getImprovementLevel()==3){
board[row+3][col+5]=I;
board[row+3][col+6]=I;
board[row+3][col+7]=I;
}
else if (square->getImprovementLevel()==4){
board[row+3][col+5]=I;
board[row+3][col+6]=V;
board[row+3][col+7]=SPACE;
}
else if (square->getImprovementLevel()>4){
board[row+3][col+5]=V;
board[row+3][col+6]=SPACE;
board[row+3][col+7]=SPACE;
}
}
else{
board[row+3][col+5]=SPACE;
board[row+3][col+6]=SPACE;
board[row+3][col+7]=SPACE;
}
if (square->getImprovementLevel()==-1 || square->isMortgaged()){
board[row+3][col+8] = M;
}
else{
board[row+3][col+8] = SPACE;
}
int count=0;
vector<shared_ptr<Player>> players = game->getPlayers();
int playerssize = players.size();
for (int i=0; i<playerssize; i++){
if (players[i]->getPosition()==square->getPosition()){
board[row+4][col+1+count]=players[i]->getPiece();
count++;
}
}
for (int i=count; i<8;i++){
board[row+4][col+1+count]=SPACE;
}
}
void TextDisplay::print(){
int numrows = board.size();
for (int i=0; i<numrows; i++){
int numcols = board[i].size();
for (int j=0; j<numcols; j++){
cout<<board[i][j];
}
cout << endl;
}
}