-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcentralwidget.cpp
More file actions
59 lines (54 loc) · 1.43 KB
/
centralwidget.cpp
File metadata and controls
59 lines (54 loc) · 1.43 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
#include "centralwidget.h"
#include <iostream>
using namespace std;
CentralWidget::CentralWidget(): QWidget()
{
//setGeometry( 0, 0, 577, 577 );
boardLabel = new QLabel( this );
boardLabel->setPixmap( QPixmap("C:\\images\\board.png") );
pieces = new QLabel*[4];
size = 0;
}
void CentralWidget::drawPieces(Player *p, int s)
{
for(int i = 0; i < s; i++)
{
if(p[i].isAlive())
{
xCoor[i] = p[i].getX();
yCoor[i] = p[i].getY();
}
else
{
xCoor[i] = -100;
yCoor[i] = -100;
}
size = s;
pName[i] = p[i].getToken();
}
update();
}
void CentralWidget::paintEvent(QPaintEvent *)
{
boardLabel->setPixmap( QPixmap("C:\\images\\board.png") );
QImage map(boardLabel->pixmap()->toImage());
QPainter painter(&map);
for(int i = 0; i < size; i++)
{
QImage img( getImageFile(pName[i]) );
painter.drawImage(xCoor[i] + 25 * (i % 2) + 8, yCoor[i] + 20 * (i / 2) + 8, img);
}
painter.end();
boardLabel->setPixmap(QPixmap::fromImage(map));
}
QString CentralWidget::getImageFile(QString piece) //display tokens corresponding to player choices
{
if(piece == "dog")
return "C:\\images\\dog.png";
else if(piece == "shoe")
return "C:\\images\\shoe.png";
else if(piece == "thimble")
return "C:\\images\\thimble.png";
else
return "C:\\images\\battleship.png";
}