-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chess.cpp
58 lines (52 loc) · 1.35 KB
/
Chess.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
#include "Chess.h"
#include "ChessBoard.h"
// default constructor (NULL_CHESS)
// uid = -1
// kindCode = -1
// both coord = (0, 0)
Chess::Chess()
{
uniqueID = NULL_CHESS;
kindCode = NULL_CHESS;
currCoord.x = 0;
currCoord.y = 0;
prevCoord.x = 0;
prevCoord.y = 0;
}
// create chess by reading file
// uid = uid
// kindCode = kind
// currCoord = loc
// prevCoord = (0 ,0)
Chess::Chess(const int32_t &uid, const int32_t &kind, const Coord &loc)
{
uniqueID = uid;
kindCode = kind;
currCoord.x = loc.x;
currCoord.y = loc.y;
prevCoord.x = 0;
prevCoord.y = 0;
}
void Chess::moveCoord(const Coord &cursorLoc)
{
// store current coord
prevCoord.x = currCoord.x;
prevCoord.y = currCoord.y;
// move to cursor's location
currCoord.x = cursorLoc.x;
currCoord.y = cursorLoc.y;
}
const int32_t Chess::getID() const { return uniqueID; }
const int32_t Chess::getKind() const { return kindCode; }
const Coord Chess::getPrevCoord() const { return prevCoord; }
const Coord Chess::getCurrCoord() const { return currCoord; }
Chess &Chess::operator=(const Chess &temp)
{
this->uniqueID = temp.uniqueID;
this->kindCode = temp.kindCode;
this->currCoord.x = temp.currCoord.x;
this->currCoord.y = temp.currCoord.y;
this->prevCoord.x = temp.prevCoord.x;
this->prevCoord.y = temp.prevCoord.y;
return *this;
}