-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiece.cpp
96 lines (63 loc) · 1.12 KB
/
Piece.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
90
91
92
93
94
95
96
#include "Piece.h"
using namespace std;
//constructors
Piece::Piece()
: teamNum(0), teamDir(8), alive(true)
{}
Piece::Piece(int tn, int td)
: teamNum(tn), teamDir(td), alive(true)
{}
//destructor
Piece::~Piece()
{}
//setters
void Piece::setAlive(bool al)
{
alive = al;
}
void Piece::setTeam(int tn)
{
teamNum = tn;
}
void Piece::setDirection(int td)
{
teamDir = td;
}
void Piece::setTeamDir(int tn, int td)
{
teamNum = tn;
teamDir = td;
}
//getters
bool Piece::getAlive()
{
return alive;
}
int Piece::getTeam()
{
return teamNum;
}
int Piece::getDirection()
{
return teamDir;
}
bool Piece::getMoveValid(int start, int end, int boardX, int takeTeam)
{
int deltaX = (abs((start % boardX) - (end % boardX)));
int deltaY = (abs((start / boardX) - (end / boardX)));
if(((deltaX + deltaY) == 1) //can move only to spaces up down left and right
&& (takeTeam == -1)) //cannot move to an occupied space
return true;
return false;
}
//methods
bool Piece::flipAlive()
{
alive = !alive;
return alive;
}
int Piece::flipDirection()
{
teamDir = teamDir * -1;
return teamDir;
}