-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDice.cpp
More file actions
33 lines (31 loc) · 668 Bytes
/
Dice.cpp
File metadata and controls
33 lines (31 loc) · 668 Bytes
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
enum Face
{
Front,Up,Back,Down,Left,Right,
};
template<typename T>
struct Dice
{
T pip[6];
T& operator[] (const Face id)
{
return pip[id];
}
const T& operator[] (const Face id) const
{
return pip[id];
}
void rotate(Face f1, Face f2, Face f3, Face f4)
{
int tmp=pip[f1];
pip[f1]=pip[f2];
pip[f2]=pip[f3];
pip[f3]=pip[f4];
pip[f4]=tmp;
}
void rollx() { rotate(Up, Front, Down, Back); }
void rollxi() { rotate(Up, Back, Down, Front); }
void rolly() { rotate(Up, Left, Down, Right); }
void rollyi() { rotate(Up, Right, Down, Left); }
void rollz() { rotate(Back, Left, Front, Right); }
void rollzi() { rotate(Back, Right, Front, Left); }
};