-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.cpp
117 lines (90 loc) · 1.5 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "Piece.h"
Piece::Piece(int b, int c, const char * bmp)
{
block = b;
color = c;
active = true;
board_pos = Utils::BlockToIndex(b);
screen_pos = Utils::BlockToScreen(b);
//Initialize pixels array on the heap
pixels = new Pixel*[BLOCK_SIZE];
for (int i = 0; i < BLOCK_SIZE; i++)
pixels[i] = new Pixel[BLOCK_SIZE];
//Load the image into the pixels array
Renderer::ReadImage(bmp, pixels);
}
Piece::~Piece()
{
for (int i = 0; i < BLOCK_SIZE; i++)
delete[] pixels[i];
delete[] pixels;
pixels = NULL;
}
bool Piece::CanMove(int block)
{
for (int i = 0; i < 64; i++)
{
if (moveset[i] == block)
return true;
}
return false;
}
void Piece::Move(int block, bool caller)
{
if(!caller)
first_move = false;
this->block = block;
board_pos = Utils::BlockToIndex(block);
screen_pos = Utils::BlockToScreen(block);
std::cout << type << " now at block " << block << std::endl;
}
Coord Piece::GetBoardPos()
{
return board_pos;
}
Coord Piece::GetScreenPos()
{
return screen_pos;
}
int Piece::GetBlock()
{
return block;
}
int Piece::GetColor()
{
return color;
}
int Piece::GetType()
{
return type;
}
int * Piece::GetMoveSet()
{
return moveset;
}
bool Piece::GetAcive()
{
return active;
}
Pixel ** Piece::GetPixels()
{
return pixels;
}
void Piece::SetBoardPos(int x, int y)
{
board_pos.x = x;
board_pos.y = y;
}
void Piece::SetScreenPos(int x, int y)
{
screen_pos.x = x;
screen_pos.y = y;
}
void Piece::SetBlock(int v)
{
block = v;
}
void Piece::SetAcive(bool v)
{
active = v;
}