-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.pde
More file actions
72 lines (71 loc) · 2.13 KB
/
tile.pde
File metadata and controls
72 lines (71 loc) · 2.13 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
70
71
72
class Tile{
//fields
int id;//location of the tile top right 0 and bottom left is n*k in a n by k grid
int x;
int y;
int type;//type of pipe
int rotation;//rotation of the tile
//only for start and end
int entrance;// where start and end enter the new tile
//constructor
Tile(int i){
this.id = i;
this.x = i % canvas_definition;
this.y = i / canvas_definition;
this.rotation = cells[this.x][this.y] % canvas_definition;
this.type = cells[this.x][this.y] / canvas_definition;
}
Tile(int i, int e){
this.id = i;
this.x = i % canvas_definition;
this.y = i / canvas_definition;
this.rotation = cells[i % canvas_definition][i / canvas_definition] % 10;
this.type = cells[i % canvas_definition][i / canvas_definition] / 10;
this.entrance = e;
}
//method
boolean connected(){
switch(this.type){
case 1:
if((this.entrance == 4 || this.entrance == 2) && (this.rotation == 1 || this.rotation == 3)){
return true;
}
if((this.entrance == 1 || this.entrance == 3) && (this.rotation == 0 || this.rotation == 2)){
return true;
}
return false;
case 2:
if((this.entrance == 1 || this.entrance == 2) && (this.rotation == 0)){
return true;
}
if((this.entrance == 2 || this.entrance == 3) && (this.rotation == 1)){
return true;
}
if((this.entrance == 3 || this.entrance == 4) && (this.rotation == 2)){
return true;
}
if((this.entrance == 4 || this.entrance == 1) && (this.rotation == 3)){
return true;
}
return false;
case 3:
if((this.entrance == 1) && !(this.rotation == 1)){
return true;
}
if((this.entrance == 2) && !(this.rotation == 2)){
return true;
}
if((this.entrance == 3) && !(this.rotation == 3)){
return true;
}
if((this.entrance == 4) && !(this.rotation == 0)){
return true;
}
return false;
case 4:
//rotation doesn't matter in a 4 Way
return true;
}
return false;
}
}