-
Notifications
You must be signed in to change notification settings - Fork 1
/
4_2_Face.ino
65 lines (65 loc) · 1.57 KB
/
4_2_Face.ino
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
class Face {
u8 face;
u8 slots[3][3];
public:
Face( u8 _face );
void setCol( u8 col, u8* newItems );
void setRow( u8 row, u8* newItems );
void draw( u8 x, u8 y );
Row getCol( u8 col );
Row getRow( u8 row );
void rotate( u8 direction );
};
Face::Face( u8 _face ){
face = _face;
for( u8 y = 0; y < 3; y++ ){
for( u8 x = 0; x < 3; x++ ){
slots[y][x] = face;
}
}
};
void Face::draw( u8 _x, u8 _y ){
// for slots draw slot in its color
for( u8 y = 0; y < 3; y++ ) {
for( u8 x = 0; x < 3; x++ ) {
pocketstar.drawRect( _x + (x*6), _y + (y*6), 5, 5, true, faceColors[ slots[ y ][ x ] ] );
}
}
};
void Face::setCol( u8 col, u8* newItems ){
for( u8 i = 0; i < 3; i++ ) {
slots[i][col] = newItems[i];
}
};
void Face::setRow( u8 row, u8* newItems ){
for( u8 i = 0; i < 3; i++ ) {
slots[row][i] = newItems[i];
}
};
Row Face::getCol( u8 col ){
u8 c[3] = { slots[0][col], slots[1][col], slots[2][col] };
Row _col ( c );
return _col;
};
Row Face::getRow( u8 row ){
u8 r[3] = { slots[row][0], slots[row][1], slots[row][2] };
Row _row ( r );
return _row;
};
void Face::rotate( u8 direction ){
if( direction == directions::clockWise ) {
Row temp0 ( getRow( 0 ) );
Row temp1 ( getRow( 1 ) );
Row temp2 ( getRow( 2 ) );
setCol( 2, temp0.get() );
setCol( 1, temp1.get() );
setCol( 0, temp2.get() );
} else {
Row temp0 ( getRow( 0 ) );
Row temp1 ( getRow( 1 ) );
Row temp2 ( getRow( 2 ) );
setCol( 0, temp0.getReverse() );
setCol( 1, temp1.getReverse() );
setCol( 2, temp2.getReverse() );
}
};