-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geolocator.java
57 lines (46 loc) · 869 Bytes
/
Geolocator.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
package client;
import java.util.Random;
public class Geolocator extends Thread {
int zone;
int direction; //0 to inside, 1 to outside
boolean inBounds = true;
Host parent;
Random rand = new Random();
public Geolocator (Host p){
parent = p;
}
@Override
public void run() {
zone = rand.nextInt(10);
direction = rand.nextInt(2);
if (direction == 0) {
direction = -1;
}
parent.setlocation(zone, direction);
while (inBounds) {
try {
Thread.sleep(rand.nextInt(10));
} catch (InterruptedException e) {
e.printStackTrace();
}
if (direction == 1) {
if (zone > 0) {
zone--;
}
else{
zone = 1;
direction = -1;
}
} else {
if (zone < 9) {
zone++;
}
else{
inBounds = false;
}
}
parent.setlocation(zone, direction);
}
parent.disconnect();
}
}