-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorld.java
65 lines (58 loc) · 1.46 KB
/
World.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
/*
* This is the World class for Test_Game.
* World is created by Test_Game, and it is then passed into Controller.
* It is essentially the model that gets displayed in Test_Game (view).
* @author gliebchen
* @version 1.0
* @since 2016-03-16
*/
public class World {
int maxRow = 0;
int maxCol = 0;
private char[][] map;
public World(int r, int c){
maxRow = r;
maxCol = c;
map = new char[maxRow+1][maxCol+1];
initialiseMap();
}
private void initialiseMap(){
//first row
for(int colCounter=maxCol;colCounter>-1;colCounter--){
map[0][colCounter]='X';
}
//middle rows
for(int rowCounter=maxRow-1;rowCounter>0;rowCounter--){
map[rowCounter][0]='X';
for(int colCounter=maxCol-1;colCounter>0;colCounter--){
map[rowCounter][colCounter]=' ';
}
map[rowCounter][maxCol]='O';
}
//last row
for(int colCounter=maxCol;colCounter>-1;colCounter--){
map[maxRow][colCounter]='X';
}
}
public char[][] getMap(){
return map;
}
public boolean isFree(int[] location){
if(map[location[0]][location[1]]==' '){
return true;
}
return false;
}
public char getWhatsInLocation(int[] location){
return map[location[0]][location[1]];
}
public void putInWorld(int[] locationAndAppearance){
map[locationAndAppearance[0]][locationAndAppearance[1]] = (char) locationAndAppearance[2];
}
public int getMaxRow(){
return maxRow;
}
public int getMaxCol(){
return maxCol;
}
}