-
Notifications
You must be signed in to change notification settings - Fork 1
/
Building.java
116 lines (97 loc) · 2.42 KB
/
Building.java
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
public class Building {
//Data
private int ROOMS_LONG;
private int ROOMS_WIDE;
private int[] cop_position = new int[2];
private int[] robber_position = new int[2];
//Methods
public Building(int rooms_wide, int rooms_long) {
this.ROOMS_WIDE = rooms_wide;
this.ROOMS_LONG = rooms_long;
//TODO: Use setter (moveCharacter) to set these
this.cop_position[0] = 0;
this.cop_position[1] = 0;
this.robber_position[0] = 0; //To later become ROOMS_WIDE-1
this.robber_position[1] = ROOMS_LONG-1;
/*ROOM LAYOUT when ROOMS_WIDE = 6, ROOMS_LONG = 4
_ _ _ _ _ _ _ _ _ _ _ _
| | | | | | |
|0,3|1,3|2,3|3,3|4,3|5,3|
| - - - - - - - - - - - |
| | | | | | |
|0,2|1,2|2,2|3,2|4,2|5,2|
| - - - - - - - - - - - | LENGTH
| | | | | | |
|0,1|1,1|2,1|3,1|4,1|5,1|
| - - - - - - - - - - - |
| | | | | | |
|0,0|1,0|2,0|3,0|4,0|5,0|
|- - - - - - - - - - - -|
WIDTH
*/
}
/* moveCharacter
* Moves the specified character in the specified direction
* Directions (0,1,2,3,4) mean (Stay, North, East, West, South) respectively
* Returns true if it is a valid move and false otherwise
* e.g. if the character is at the leftmost wall, asking them
* to move left should return false and not change their position
*/
Boolean moveCharacter (Boolean cop, int direction) {
/*if cop
move the cop
else
move the robber
*/
int[] characterToMove;
if(cop){
characterToMove = cop_position;
} else {
characterToMove = robber_position;
}
if (direction == 0){
//Stay where you are
return true;
}
else if(direction == 1) {
if (characterToMove[1] > ROOMS_LONG - 2) {
//if we are on the Northern edge
return false;
}
else {
characterToMove[1] += 1;
return true;
}
}
else if(direction == 2) {
}
else if(direction == 3) {
}
else if(direction == 4) {
}
else if(direction == 5) {
}
else {
return false;
}
return false;
}
//Getter that returns cop or robber pos
int[] getCharacterPos (Boolean cop) {
/*if cop
return cop's position
else
return robber's position
*/
int[] characterToGet;
if(cop){
characterToGet = cop_position;
} else {
characterToGet = robber_position;
}
//Clone method ensures we only pass a copy of the cop/robber position
//So it cant be editted
int[] position = characterToGet.clone();
return position;
}
}