-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardMain.cpp
More file actions
137 lines (125 loc) · 2.83 KB
/
BoardMain.cpp
File metadata and controls
137 lines (125 loc) · 2.83 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "BoardMain.h"
#include "AllegroWrap.h"
CBoardMain::CBoardMain()
{
_init();
_initNotification();
}
CBoardMain::~CBoardMain()
{
}
//----------------------private functions-----------------------//
void CBoardMain:: _init()
{
board.resize(countCells);
for(int i = 0; i < countCells; i++)
board[i].resize(countCells);
for(int i = 0; i < countCells; i++)
{
for(int j = 0; j < countCells; j++)
{
board[i][j].idPiece = idEmpty;
board[i][j].x = i;
board[i][j].y = j;
}
}
};
void CBoardMain::_initNotification()
{
wordsNotificat.resize(9);
numbersNotificat.resize(9);
wordsNotificat[0] = " ";
wordsNotificat[1] = "a";
wordsNotificat[2] = "b";
wordsNotificat[3] = "c";
wordsNotificat[4] = "d";
wordsNotificat[5] = "e";
wordsNotificat[6] = "f";
wordsNotificat[7] = "g";
wordsNotificat[8] = "h";
numbersNotificat[0] = " ";
numbersNotificat[1] = "1";
numbersNotificat[2] = "2";
numbersNotificat[3] = "3";
numbersNotificat[4] = "4";
numbersNotificat[5] = "5";
numbersNotificat[6] = "6";
numbersNotificat[7] = "7";
numbersNotificat[8] = "8";
}
//----------------------public functions-----------------------//
void CBoardMain::deleteIDPiece(int aI, int aJ)
{
board[aI][aJ].idPiece = -1;
};
void CBoardMain::clearBoard()
{
for(int i = 1; i < countCells; i++)
{
for(int j = 1; j < countCells; j++)
{
board[i][j].idPiece = -1;
}
}
};
//----------------------set and get functions-----------------------//
void CBoardMain::setPieces(vector<CPiece *> aVectorPieces)
{
int sizeVector = aVectorPieces.size();
int indexVector = 0;
int intColor = 0; // for white vector and intColor = 100 for ID of Black pieces
if(aVectorPieces[0]->getColor() == WHITE)
intColor = 0;
else
intColor = 100;
int tempX = 0;
int tempY = 0;
for(int i = 0; i < sizeVector; i++)
{
if(aVectorPieces[i]->getLive())
{
tempX = aVectorPieces[i]->getX();
tempY = aVectorPieces[i]->getY();
board[tempX][tempY].idPiece = i + intColor;
}
}
};
const sCell &CBoardMain::getCell(int aI, int aJ)const
{
return board[aI][aJ];
};
const char CBoardMain::getIDPiece( int aI, int aJ)const
{
return board[aI][aJ].idPiece;
};
void CBoardMain:: setIDPiece(int aI, int aJ, char aID)
{
board[aI][aJ].idPiece = aID;
};
vector<vector<sCell>>*CBoardMain:: getPtrBoard()
{
return &board;
};
//----------------draw functions-------------------------------//
void CBoardMain:: draw()
{
CAllegroWrap &inst = CAllegroWrap::instance();
inst.drawRectangle(50, 50, 400, 400);
for(int i = 0; i < countCells; i++)
for(int j = 0; j < countCells; j++ )
{
if(j == 0 && i == 0)
continue;
if(i == 0)
{
inst.drawString(numbersNotificat[9 - j], 0 + 20, j * sizeCell + 20);
continue;
}
if(j == 0)
{
inst.drawString(wordsNotificat[i], i * sizeCell + 20, 0 + 20);
continue;
}
inst.drawCell(this->getCell(i, j));
}
}