-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCube.cpp
More file actions
69 lines (54 loc) · 1.99 KB
/
Copy pathCube.cpp
File metadata and controls
69 lines (54 loc) · 1.99 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
63
64
65
66
67
68
69
#include <iostream>
#include "Cube.hpp"
Cube::Cube(int width, int depth, int height) {
this->width = width;
this->depth = depth;
this->height = height;
for(int x = 0; x < width; x++) {
for(int y = 0; y < depth; y++) {
for(int z = 0; z < height; z++) {
cuboids[x][y][z].shape = NULL;
}
}
}
}
bool Cube::checkShape(Shape *shape, int rotation, int x, int y, int z){
Rotation *rot = shape->rotations[rotation];
for(int bi = 0; bi < rot->numBlocks; bi ++) {
int cx = rot->blocks[bi].x + x;
int cy = rot->blocks[bi].y + y;
int cz = rot->blocks[bi].z + z;
if( cx >= this->width ||
cy >= this->depth ||
cz >= this->height ||
this->cuboids[cx][cy][cz].shape != NULL)
return false;
}
return true;
}
void Cube::removeShape(Shape *shape, int rotation, int x, int y, int z){
Rotation *rot = shape->rotations[rotation];
for(int bi = 0; bi < shape->rotations[rotation]->numBlocks; bi ++) {
int cx = rot->blocks[bi].x + x;
int cy = rot->blocks[bi].y + y;
int cz = rot->blocks[bi].z + z;
this->cuboids[cx][cy][cz].shape = NULL;
}
}
bool Cube::putShape(Shape *shape, int rotation, int x, int y, int z){
if (this->checkShape(shape, rotation, x, y, z)) {
Rotation *rot = shape->rotations[rotation];
for(int bi = 0; bi < shape->rotations[rotation]->numBlocks; bi ++) {
int cx = rot->blocks[bi].x + x;
int cy = rot->blocks[bi].y + y;
int cz = rot->blocks[bi].z + z;
this->cuboids[cx][cy][cz].shape = shape;
this->cuboids[cx][cy][cz].x = x;
this->cuboids[cx][cy][cz].y = y;
this->cuboids[cx][cy][cz].z = z;
this->cuboids[cx][cy][cz].rotation = rotation;
}
return true;
}
return false;
}