-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemi5.java
More file actions
47 lines (46 loc) · 1.38 KB
/
Semi5.java
File metadata and controls
47 lines (46 loc) · 1.38 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
import java.util.Random;
public class Semi5 {
static int[][] createEmptyMap(int rows,int columns){
return new int[rows][columns];
}
static void createOutlineMap(int[][] map){
for (int i = 0; i < map[0].length; i++) {
map[0][i] = -1;
map[map.length-1][i] = -1;
}
for (int i = 0; i < map.length; i++) {
map[i][0] = -1;
map[i][map[i].length-1] = -1;
}
}
static void createWall(int[][] map){
int row = new Random().nextInt(2,map.length);
int column = new Random().nextInt(3, map[0].length);
for (int i = row; i < map.length-4; i++) {
map[i][column] = -1;
}
for (int i = column; i < map[0].length-4; i++) {
map[row][i] = -1;
}
}
static void printMap(int[][] map){
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
System.out.printf("%d\t",map[i][j]);
}
System.out.println();
}
}
static int[][] getMap(int rows,int columns){
int[] map[] = createEmptyMap(rows,columns);
createOutlineMap(map);
createWall(map);
createWall(map);
createWall(map);
return map;
}
public static void main(String[] args) {
int[] map[] = getMap(10,15);
printMap(map);
}
}