-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnowPlow.java
More file actions
executable file
·53 lines (46 loc) · 1.28 KB
/
Copy pathSnowPlow.java
File metadata and controls
executable file
·53 lines (46 loc) · 1.28 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
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 SnowPlow extends Vehicle {
@Override
public void reportPlaceError() {
System.out.println(VehicleError.SNOWPLOWPLACEMENT);
}
@Override
public void reportMoveError() {
System.out.println(VehicleError.SNOWPLOWERROR);
}
//
@Override
public boolean place(City city, Point location, Direction facing) {
//snowplows are not allowed to be placed on SNOWEDROAD or OFFROAD tiles or out of city
if (super.place(city, location, facing)){
if (city.isSnowed(location)) {
city.clearSnow(location);
}
//System.out.println("snowplow placed");
return true;
}
return false;
}
@Override
//
public boolean move() {
if (super.move()) {
if (city.isSnowed(location.translate(facing))) {
location = location.translate(facing);
city.clearSnow(location);
//System.out.println("snowplow cleared during move");
return true;
}
location = location.translate(facing);
return true;
}
return false;
}
public String toString(){
return "SnowPlow "+location;
}
}