-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
158 lines (128 loc) · 3.59 KB
/
main.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <QApplication>
#include "mainwindow.h"
#include "tile.h"
int count=0,turn=1,exp[60],max=0;
int wR,wC,bR,bC;
Tile *click1;
Tile *tile[8][8] = { { NULL } };
class Border
{
public:
Border();
void outline(QWidget *baseWidget, int xPos, int yPos, int Pos)
{
QLabel *outLabel = new QLabel(baseWidget);
if(!Pos)
outLabel->setGeometry(xPos,yPos,552,20); //Horizontal Borders
else
outLabel->setGeometry(xPos,yPos,20,512); //Vertical Borders
outLabel->setStyleSheet("QLabel { background-color :rgb(170, 170, 127); color : black; }");
}
};
void accessories(QWidget *baseWidget)
{
QLabel *player2 = new QLabel(baseWidget);
QLabel *name2 = new QLabel("Player 2", baseWidget);
QLabel *time2 = new QLabel("00:00:00", baseWidget);
QLabel *player1 = new QLabel(baseWidget);
QLabel *name1 = new QLabel("Player 1", baseWidget);
QLabel *time1 = new QLabel("00:00:00", baseWidget);
QLabel *moves = new QLabel(baseWidget);
name1->setGeometry(125,610,80,20);
time1->setGeometry(120,635,80,20);
player1->setGeometry(100,500,100,100);
player1->setPixmap(QPixmap(":/Images/profile.png"));
name2->setGeometry(125,210,80,20);
time2->setGeometry(120,235,80,20);
player2->setGeometry(100,100,100,100);
player2->setPixmap(QPixmap(":/Images/profile.png"));
moves->setGeometry(1000,105,250,550);
moves->setStyleSheet("QLabel {background-color: white;}");
}
void chessBoard(QWidget *baseWidget, Tile *tile[8][8])
{
int i,j,k=0,hor,ver;
Border *border[4]={ NULL };
//borderDisplay
{
border[0]->outline(baseWidget,330,105,0);
border[1]->outline(baseWidget,330,637,0);
border[2]->outline(baseWidget,330,125,1);
border[2]->outline(baseWidget,862,125,1);
}
//Create 64 tiles (allocating memories to the objects of Tile class)
ver=125;
for(i=0;i<8;i++)
{
hor=350;
for(j=0;j<8;j++)
{
tile[i][j] = new Tile(baseWidget);
tile[i][j]->tileColor=(i+j)%2;
tile[i][j]->piece=0;
tile[i][j]->row=i;
tile[i][j]->col=j;
tile[i][j]->tileNum=k++;
tile[i][j]->tileDisplay();
tile[i][j]->setGeometry(hor,ver,64,64);
hor+=64;
}
ver+=64;
}
//white pawns
for(j=0;j<8;j++)
{
tile[1][j]->piece=1;
tile[1][j]->pieceColor=0;
tile[1][j]->display('P');
}
//black pawns
for(j=0;j<8;j++)
{
tile[6][j]->piece=1;
tile[6][j]->pieceColor=1;
tile[6][j]->display('P');
}
//white and black remaining elements
for(j=0;j<8;j++)
{
tile[0][j]->piece=1;
tile[0][j]->pieceColor=0;
tile[7][j]->piece=1;
tile[7][j]->pieceColor=1;
}
{
tile[0][0]->display('R');
tile[0][1]->display('H');
tile[0][2]->display('B');
tile[0][3]->display('Q');
tile[0][4]->display('K');
tile[0][5]->display('B');
tile[0][6]->display('H');
tile[0][7]->display('R');
}
{
tile[7][0]->display('R');
tile[7][1]->display('H');
tile[7][2]->display('B');
tile[7][3]->display('Q');
tile[7][4]->display('K');
tile[7][5]->display('B');
tile[7][6]->display('H');
tile[7][7]->display('R');
}
wR=7;
wC=4;
bR=0;
bC=4;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *myWidget = new QWidget();
myWidget->setGeometry(0,0,1370,700);
accessories(myWidget);
chessBoard(myWidget,tile);
myWidget->show();
return a.exec();
}