-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftSnowPlow.java
More file actions
executable file
·64 lines (58 loc) · 1.6 KB
/
Copy pathLeftSnowPlow.java
File metadata and controls
executable file
·64 lines (58 loc) · 1.6 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
package edu.brandeis.cs12b.pa4;
import edu.brandeis.cs12b.pa4.provided.City;
import edu.brandeis.cs12b.pa4.provided.Direction;
import edu.brandeis.cs12b.pa4.provided.Point;
import edu.brandeis.cs12b.pa4.provided.VehicleError;
public class LeftSnowPlow extends SnowPlow {
// public LeftSnowPlow (City city) {
// super(city);
// }
@Override
public void reportPlaceError() {
System.out.println(VehicleError.LEFTSNOWPLOWPLACEMENT);
}
@Override
public void reportMoveError() {
System.out.println(VehicleError.LEFTSNOWPLOWERROR);
}
@Override
//
public boolean move() {
Point newLocation = location.translate(facing);
//System.out.println(facing);
Direction newFacing = Turn(facing);
//System.out.println(newLocation);
if (newLocation.x>city.maxX || newLocation.y>city.maxY) {
reportMoveError();
return false;
} else if (city.isSnowed(newLocation)) {
city.clearSnow(newLocation);
} else if (city.isOffRoad(newLocation)) {
newLocation=location.translate(newFacing);
if (city.isOffRoad(newLocation)) {
reportMoveError();
return false;
} else if (city.isSnowed(newLocation)) {
city.clearSnow(newLocation);
}
facing=newFacing;
}
//System.out.println("Leftsnowplow cleared during move");
location = newLocation;
return true;
}
//turn left
public Direction Turn(Direction facing) {
switch (facing){
case NORTH: return Direction.WEST;
case SOUTH: return Direction.EAST;
case EAST: return Direction.NORTH;
case WEST: return Direction.SOUTH;
default: break;
}
return null;
}
public String toString(){
return "LeftSnowPlow "+location;
}
}