-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.cpp
More file actions
63 lines (55 loc) · 1.19 KB
/
dice.cpp
File metadata and controls
63 lines (55 loc) · 1.19 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
#include "dice.h"
#include "diceanimation.h"
#include "spot.h"
#include <QDebug>
#include <QMouseEvent>
#include <QLabel>
#include <QTimer>
Dice::Dice(int num, Where where, QWidget * parent):
ClickableLabel(parent),
number(num)
{
setPixmap(QPixmap(":/images/dicea.png"));
if (where == TOP) move(453,281);
else move(453,331);
for (int i=0; i<8; ++i){
spots[i] = new Spot(i+1, this);
}
setNumber(number);
}
void Dice::setNumber(const int number) const {
for (int i=0; i<8; ++i)
spots[i]->hide();
QList<int> showThese;
switch (number){
case 1:
showThese << 0;
break;
case 2:
showThese << 3 << 4;
break;
case 3:
showThese << 0 << 3 << 4;
break;
case 4:
showThese << 1 << 3 << 4 << 6;
break;
case 5:
showThese << 0 << 1 << 3 << 4 << 6;
break;
case 6:
showThese << 1 << 2 << 3 << 4 << 5 << 6;
break;
}
foreach (int showThis, showThese)
spots[showThis]->show();
}
void Dice::roll() const {
setNumber(((int)(drand48()*6))+1);
}
void Dice::changeStyle(const char codeletter) {
setPixmap(QString(":/images/dice") + codeletter + QString(".png"));
for (int i=0; i<8; ++i){
spots[i]->changeStyle(codeletter);
}
}