-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegionController.java
More file actions
42 lines (35 loc) · 1.27 KB
/
RegionController.java
File metadata and controls
42 lines (35 loc) · 1.27 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
import java.awt.*;
import javax.swing.*;
public class RegionController {
private Region[] regions;
public RegionController(String inputFile){
StdIn.setFile(inputFile);
int j = Integer.parseInt(StdIn.readString()); //number of regions
regions = new Region[j];
for (int i = 0; i < j; i++){
int x = Integer.parseInt(StdIn.readString());
int y = Integer.parseInt(StdIn.readString());
int w = Integer.parseInt(StdIn.readString());
int h = Integer.parseInt(StdIn.readString());
String name = StdIn.readString(); //might have to adjust for names with several words
//add description and solved param later
regions[i] = new Region(x,y,w,h,name);
}
}
public Region[] getRegions() { return regions; }
public int countSolvedRooms(){
int count = 0;
for ( Region next : regions ){
if (next.isSolved()) { count++; }
}
return count;
}
public Region find(Point p){ //find the region that contains point
for ( Region next : regions ){
Rectangle r = next.getRectangle();
boolean hasIt = r.contains(p);
if (hasIt){ return next; }
}
return null;
}
}