-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
101 lines (78 loc) · 2.49 KB
/
Copy pathShape.java
File metadata and controls
101 lines (78 loc) · 2.49 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.awt.Color;
import java.util.LinkedList;
import java.awt.Graphics;
// ====================== Enum Classes ====================== //
// different shape types (must add other shapes here if wanted and use a custom labyrinthGerenator method)
enum Type {
HEXAGON(6),
SQUARE(4),
TRIANGLE(3);
private int value;
Type(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
// sets the color of different shapes depending on the Visited state
enum Explored {
NEVER(Color.decode("#1A2A4F")),
PARTIALLY(Color.decode("#F7A5A5")),
FULLY(Color.decode("#FFF2EF"));
private Color color;
Explored(Color color) {
this.color = color;
}
public Color getColor() {
return this.color;
}
}
abstract class Shape {
protected int length;
protected Type type;
protected int i, j;
protected Explored explored = Explored.NEVER;
protected LinkedList<Shape> neighbors = new LinkedList<>();
protected boolean[] isConnected;
protected Shape(int length, Type type, int i, int j) {
this.length = length;
this.type = type;
this.i = i;
this.j = j;
}
// ====================== Boolean Methods ====================== //
// Checks if the node is not explored, partially explored or fully explored
public boolean isFullyExplored() {
return this.explored == Explored.FULLY;
}
public boolean isNeverExplored() {
return this.explored == Explored.NEVER;
}
// ====================== Void Methods ====================== //
public void setExplored(Explored explored) {
this.explored = explored;
}
public void addNeighbor(Shape neighbor, int index) {
if (index >= 0 && index < neighbors.size()) {
neighbors.set(index, neighbor);
}
}
public void connectNeighbor(Shape neighbor) {
if (neighbor == null) return;
int position = neighbors.indexOf(neighbor);
isConnected[position] = true;
int opposite = neighbor.neighbors.indexOf(this);
neighbor.isConnected[opposite] = true;
}
// ====================== Get Methods ====================== //
public Type getType() {
// not used for this project
return type;
}
public LinkedList<Shape> getNeighbors() {
return neighbors;
}
// Every subclass must implement this method
public abstract void draw(Graphics g);
}