-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouse.java
More file actions
240 lines (224 loc) · 7.7 KB
/
Copy pathHouse.java
File metadata and controls
240 lines (224 loc) · 7.7 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import processing.core.PApplet;
import processing.core.PImage;
import java.util.Random;
public class House {
private PApplet sketch;
private int x;
private int y;
private String name;
private String address;
private int time;
private int timeDelivery = 10;
private Order order;
private OrderList list;
private DoubleLinkedNode node;
private int lastTickTime = 0;
private boolean isDelivery = false;
private static int delivering;
private boolean canCancel = true;
PImage Receiver;
PImage Priority;
public House(int x, int y, String name, String address) // Constructor with specific data stored
{
this.x = x;
this.y = y;
this.name = name;
this.address = address;
this.order = null;
}
public House(String name, String address) // Constructor with randomized data stored
{
Random ran = new Random();
this.x = ran.nextInt(20, 600);
this.y = ran.nextInt(20, 700);
this.name = name;
this.address = address;
this.order = null;
}
public void setTime(int time) // Sets up the time
{
this.time = time;
}
public void setSketch(PApplet sketch) // Sets up sketch
{
this.sketch = sketch;
}
public void setOrder(Order order) // Sets up order
{
this.order = order;
}
public void setList(OrderList list)
{
this.list = list;
if(list.getScore() >= 15) // Makes sure that no matter what, you can't exceed the daily limit (Not trying to over work anyone)
{
this.list = null;
this.time = 0;
this.timeDelivery = 0;
this.x = 0;
this.y = 0;
this.name = null;
this.address = null;
this.order= null;
this.node = null;
}
}
public void setNode(DoubleLinkedNode node) // Sets up node
{
this.node = node;
}
public void timeTick() // Time goes down by one second
{
if (time > 0) {
time--;
}
}
public int getX() // Returns the x coordinates
{
return this.x;
}
public int getY() // Returns the y coordinates
{
return this.y;
}
public void cancelled() // The order is not delivered but cancelled, scores doesn't get added, nodes gets removed from the list
{
if(canCancel)
{
list.removeNode(node);
this.name = "DNE";
this.address = "DNE";
this.time = 0;
this.order = null;
this.timeDelivery = 0;
this.delivering = 0;
this.canCancel = false;
}
}
public void finished() // The order is successfully delivered, scores gets added, nodes gets removed from the list
{
list.finishOrder(node);
this.name = "Delivered";
this.address = "Delivered";
this.time = 0;
this.order = null;
this.timeDelivery = 0;
this.delivering = 0;
}
public void display() { // Displaying all the graphics for the people on the map and their stats
sketch.stroke(1);
sketch.fill(255, 0, 0);
if(list != null && list.getHead() != null && order == list.getHead().getValue()) // If it's head of the list and the most prioritised
{
sketch.fill(0,0,255);
Priority = sketch.loadImage("images/Priority.png");
sketch.image(Priority, x, y, 20, 40);
}
else // Everyone else who isn't prioritised yet
{
sketch.fill(255, 0, 0);
Receiver = sketch.loadImage("images/Receiver.png");
sketch.image(Receiver, x, y, 20, 40);
}
timerTick();
if (sketch.mouseX >= x && sketch.mouseX <= x + 40 && sketch.mouseY >= y && sketch.mouseY <= y + 40) // If the mouse hovers over the person
{
sketch.fill(57, 255, 20);
sketch.textSize(18);
String infoText = "";
if(order != null) // If the order exists, show the stats of the person
{
infoText = order.toString1() + "\nReceiver's Name: " + name + "\nAddress: " + address;
}
else
{
infoText = "Receiver's Name: " + name + "\nAddress: " + address;
}
if (y < 80) { // Making sure that it's visible anywhere
sketch.fill(0,0,0,120);
sketch.rect(x - 10, y + 40, 200, 50);
sketch.rect(x + 22, y + 10, 90, 20);
sketch.textSize(15);
sketch.fill(57, 255, 20);
sketch.text("Time: " + time, x + 45, y + 25);
sketch.fill(57, 255, 20);
sketch.text(timeDelivery, x + 25, y + 25);
sketch.textSize(12);
if(x > 650)
{
sketch.fill(57, 255, 20);
sketch.text(infoText, x - 30, y + 55);
}
else
{
sketch.fill(57, 255, 20);
sketch.text(infoText, x - 5, y + 55);
}
}
else{
sketch.fill(0,0,0,120);
sketch.rect(x - 10, y - 50, 200, 50);
sketch.rect(x + 22, y + 10, 90, 20);
sketch.fill(57, 255, 20);
sketch.textSize(15);
sketch.text("Time: " + time, x + 45, y + 25);
sketch.text(timeDelivery, x + 25, y + 25);
sketch.textSize(12);
if(x > 650)
{
sketch.fill(57, 255, 20);
sketch.text(infoText, x - 30, y - 35);
sketch.fill(0,0,0,120);
sketch.rect(x - 40, y - 50, 200, 50);
sketch.rect(x + 22, y + 10, 90, 20);
}
else
{
sketch.fill(57, 255, 20);
sketch.text(infoText, x - 5, y - 35);
}
}
if(sketch.key == 'f' && timeDelivery > 0 && delivering == 0) // If f is pressed, then it started delivering
{
this.isDelivery();
sketch.key = 's';
}
if(sketch.key == ' ' && time - timeDelivery >= 0 && isDelivery) // Only for testing as a programmer as it doesn't give accurate stats of score
{
sketch.key = 's';
finished();
sketch.key = 's';
}
}
}
public void isDelivery() // An order is getting delivered, this is the set up so that no other deliveries can happen at the same time
{
this.isDelivery = true;
delivering = 1;
}
public void timerTick() // Time goes down by one second
{
try
{
if (sketch.millis() - lastTickTime >= 1000) {
lastTickTime = sketch.millis();
if(isDelivery && timeDelivery > 0) // If there's a counting down of a delivery time, count down here
{
this.timeDelivery--;
}
if (time <= 0) { // If the order is not delivered but the customers got tired of waiting, they cancel (Player doesn't receive points)
cancelled();
}
if(timeDelivery == 0 && order != null) // If the order is successfully delivered, player gets points
{
finished();
this.delivering = 0;
}
}
}
catch(NullPointerException exception) // If there's an error, it won't stop the program
{
System.out.println("null house bro");
}
}
}