-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCity.java
More file actions
executable file
·84 lines (71 loc) · 2.03 KB
/
Copy pathCity.java
File metadata and controls
executable file
·84 lines (71 loc) · 2.03 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
package edu.brandeis.cs12b.pa4.provided;
import java.util.Arrays;
import edu.brandeis.cs12b.pa4.Vehicle;
import edu.brandeis.cs12b.pa4.provided.Point;
public class City {
public int maxX;
public int maxY;
private int[][] layout;
private final int SNOWEDROAD = 1;
private final int CLEAREDROAD = 2;
private final int OFFROAD = 0;
/*
* NOTE: THE CITY CLASS IS FULLY IMPLEMENTED FOR YOU. YOU SHOULD NOT CHANGE IT!
*/
/**
* Create a new city with a given layout
* @param layout the layout for the new city
*/
public City(int[][] layout){
this.layout = layout;
this.maxY = this.layout.length;
this.maxX = this.layout[0].length;
}
/**
* Checks to see if a given location is a wall
* @param location to check
* @return true if the location is a wall, false if it isn't
*/
public boolean isOffRoad(Point location){
return (this.layout[location.y][location.x] == OFFROAD);
}
/**
* Checks to see if a given location is covered in snow
* @param location to check
* @return true if the location is snowed, false if it isn't
*/
public boolean isSnowed(Point location){
return (this.layout[location.y][location.x] == SNOWEDROAD);
}
/**
* Clears a road of snow
* @param location to clear
* @return true if the location was successfully cleared of snow,
* false if it failed for some reason
*/
public boolean clearSnow(Point location){
if(this.layout[location.y][location.x] == SNOWEDROAD){
this.layout[location.y][location.x] = CLEAREDROAD;
return true;
} else return false;
}
/**
* Checks to see if all the city's streets are cleared of snow
* @return true if all roads are clear, false if not
*/
public boolean isClear(){
for(int[] arr2: this.layout)
{
for(int value: arr2)
if (value == SNOWEDROAD)
return false;
}
return true;
}
/**
* returns a string representation of the city
*/
public String toString(){
return Arrays.deepToString(this.layout);
}
}