-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.cc
84 lines (69 loc) · 1.92 KB
/
board.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
#include "board.h"
const int MAX_TIMS_CUPS = 4;
const int NUM_SQUARES = 40;
const int MAX_PLAYERS = 8;
Board::Board() {
sqrImproves = {
{"AL", 0}, {"ML", 0}, {"ECH", 0}, {"PAS", 0}, {"HH", 0}, {"RCH", 0},
{"DWE", 0}, {"CPH", 0}, {"LHI", 0}, {"BMH", 0}, {"OPT", 0}, {"EV1", 0},
{"EV2", 0}, {"EV3", 0}, {"PHYS", 0}, {"B1", 0}, {"B2", 0}, {"EIT", 0},
{"ESC", 0}, {"C2", 0}, {"MC", 0}, {"DC", 0}
};
bd = std::make_unique<BoardDisplay> ();
}
void Board::updateInfo(){
for (auto &p: sqrImproves){
if (p.second > 0){
int index = indexOfSquare(p.first);
int sqrC = colOfSquare(index);
int sqrR = rowOfSquare(index);
int r = sqrR + 1;
for (int i = 0; i < p.second; i++){
int c = sqrC + i;
bd->addImpr(r, c);
}
}
}
// keeps track of number of players at each square,
// increments when another player is found at that square
// e.g. 0 : 1, 32: 5, 12: 2
map<int, int> numPlayers;
for (auto &p: playerPos){
int sqrC = colOfSquare(p.second);
int sqrR = rowOfSquare(p.second);
auto it = numPlayers.find(p.second);
int c = sqrC;
if (it != numPlayers.end()){
c += it->second;
numPlayers[p.second]++;
} else {
numPlayers[p.second] = 1;
}
int r = sqrR + 4;
bd->addPlayer(r, c, p.first);
}
}
void Board::drawBoard(){
updateInfo();
bd->draw();
bd->reset();
}
void Board::addPlayer( char player ){
playerPos[player] = 0;
}
void Board::removePlayer( char player ){
playerPos.erase(player);
}
void Board::movePlayer(char gamepiece, int newSqr) {
playerPos[gamepiece] = newSqr;
return;
}
void Board::removeImpr( string building ){
sqrImproves[building]--;
}
void Board::addImpr( string building ){
sqrImproves[building]++;
}
int Board::getImpr( string building ){
return sqrImproves[building];
}