-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameBoardc.cpp
More file actions
60 lines (54 loc) · 791 Bytes
/
GameBoardc.cpp
File metadata and controls
60 lines (54 loc) · 791 Bytes
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
#include "GameBoard.h"
void GameBoard::clear()
{
for(char &i : board)
{
i = EMPTY;
}
}
GameBoard::GameBoard(int w, int h)
{
width = w;
height = h;
board.resize(w*h);
clear();
}
ostream& operator<<(ostream &os, GameBoard &gb)
{
for(int i = 0; i < gb.board.capacity(); ++i)
{
os << '|' << gb.board.at(i);
if(((i+1)%gb.width) == 0)
{
os << '|' << endl;
}
}
return os;
}
void GameBoard::chaPiece(int i, char c)
{
if(board.at(i - 1) == EMPTY)
{
board.at(i - 1) = c;
}
else
{
state = "Position already filled.";
}
}
void GameBoard::movPiece(int i, int j)
{
if(board.at(j - 1) == EMPTY)
{
board.at(j - 1) = board.at(i - 1);
board.at(i - 1) = EMPTY;
}
else
{
state = "Position already filled.";
}
}
string GameBoard::getState()
{
return state;
}