-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.cpp
52 lines (45 loc) · 1.2 KB
/
Shape.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
#include "Shape.h"
// Constructor
Shape::Shape() {
rotation = 0;
}
// height()
int Shape::height() const {
return shape_height[rotation];
}
// width()
int Shape::width() const {
return shape_width[rotation];
}
// &height()
int& Shape::height() {
return shape_height[rotation];
}
// &width()
int& Shape::width() {
return shape_width[rotation];
}
// direction is -1 for left, and +1 for right
void Shape::rotate(int direction) {
rotation += direction;
if (rotation < 0) {
rotation = 3;
} else if (rotation > 3) {
rotation = 0;
}
}
// return the shape_data character at row, col
// Take a look at the Ruminations on C++ Book, Chapter 9, for the
// inspiration of this method
char Shape::shapedata(int row, int col) const {
return (shape_data[rotation][(row*shape_width[rotation])+col]);
}
char& Shape::shapedata(int row, int col) {
return (shape_data[rotation][(row*shape_width[rotation])+col]);
}
// This is meant for initialization routines. It returns a reference to
// shape_data for the current "rotation." See init_shape() routines in the
// various shapes.
string& Shape::shapedata() {
return shape_data[rotation];
}