-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplorer.java
More file actions
120 lines (108 loc) · 1.85 KB
/
Explorer.java
File metadata and controls
120 lines (108 loc) · 1.85 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
public class Explorer
{
private int x;
private int y;
private int turns;
private Location loc;
public final int ZERO = 1;
public final int NINETY = 2;
public final int ONEEIGHTY = 3;
public final int TWOSEVENTY = 4;
private int facing;
public Explorer(Location loc)
{
this.loc = loc;
x = loc.getX();
y = loc.getY();
facing = ZERO;
turns = 0;
}
public int getX(){return loc.getX();}
public int getY(){return loc.getY();}
public int getR(){return loc.getY()/5;}
public int getC(){return loc.getX()/5;}
public int getPotentialX(){return x;}
public int getPotentialY(){return y;}
public void addTurns(int a){turns+=a;}
public Location getLocation(){return loc;}
public void setLocation(Location loc){this.loc = loc;}
public int getMoves(){return turns;}
public void move()
{
switch(facing)
{
case 1:
loc.setX(5);
break;
case 2:
loc.setY(-5);
break;
case 3:
loc.setX(-5);
break;
case 4:
loc.setY(5);
break;
}
x = loc.getX();
y = loc.getY();
turns++;
}
public void potentialMove()
{
x = loc.getX();
y = loc.getY();
switch(facing)
{
case 1:
x+=5;
break;
case 2:
y-=5;
break;
case 3:
x-=5;
break;
case 4:
y+=5;
break;
}
}
public void turnLeft()
{
switch(facing)
{
case 1:
facing = NINETY;
break;
case 2:
facing = ONEEIGHTY;
break;
case 3:
facing = TWOSEVENTY;
break;
case 4:
facing = ZERO;
break;
}
}
public void turnRight()
{
switch(facing)
{
case 1:
facing = TWOSEVENTY;
break;
case 2:
facing = ZERO;
break;
case 3:
facing = NINETY;
break;
case 4:
facing = ONEEIGHTY;
break;
}
}
public int getFacing(){return facing;}
}