-
Notifications
You must be signed in to change notification settings - Fork 1
/
Room.java
140 lines (113 loc) · 3.19 KB
/
Room.java
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//Room class provides a 'node' data structuer with information about the rooms
//Each room has a certain gameboard space associated with it, along with links to
//other rooms via cardinal directions.
//
import java.awt.*;
public class Room {
//top left corner
private int posX;
private int posY;
private boolean visibility;
public static int size = 130;
public static int doorWidth = 50;
public static int doorHeight = 5;
public static int space = (size - doorWidth) / 2;
private Room north;
private Room south;
private Room east;
private Room west;
public Room(int x, int y) {
posX = x;
posY = y;
visibility = false;
}
//~~~~~~~~~~Setters~~~~~~~~~~~~~~~~~
public void setVisibility() {
visibility = true;
}
public void setEast(Room r) {
east = r;
}
public void setWest(Room r) {
west = r;
}
public void setSouth(Room r) {
south = r;
}
public void setNorth(Room r) {
north = r;
}
//~~~~~~~~~~Getters~~~~~~~~~~~~~~~~~
public int getX() {
return posX;
}
public int getY() {
return posY;
}
public static int getSize() {
return size;
}
public boolean getVisibility() {
return visibility;
}
public Room getEast() {
return east;
}
public Room getWest() {
return west;
}
public Room getNorth() {
return north;
}
public Room getSouth() {
return south;
}
public int getIndX() {
return (int) Math.floor(posX / size);
}
public int getIndY() {
return (int) Math.floor(posY / size);
}
public void draw(Graphics g) {
if (visibility) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(posX, posY, size, size);
g.setColor(Color.BLACK);
g.drawRect(posX, posY, size, size);
g.setColor(Color.ORANGE);
if (north != null) {
g.fillRect(posX + space, posY, doorWidth, doorHeight);
}
if (south != null) {
g.fillRect(posX + space, posY + size - doorHeight, doorWidth, doorHeight);
}
if (east != null) {
g.fillRect(posX + size - doorHeight, posY + space, doorHeight, doorWidth);
}
if (west != null) {
g.fillRect(posX, posY + space, doorHeight, doorWidth);
}
} else {
g.setColor(Color.DARK_GRAY);
g.fillRect(posX, posY, size, size);
}
}
@Override
public boolean equals(Object o) {
if (o == null || this.getClass() != o.getClass()) {
return false;
} else {
Room p = (Room) o;
boolean b = (this.getX() == p.getX() && this.getY() == p.getY());
return b;
}
}
@Override
public int hashCode() {
int prime = 31;
int result = prime + size;
result = result * prime + this.getX();
result = result * prime + this.getY();
return result;
}
}