-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabyrinth.java
More file actions
74 lines (66 loc) · 2.12 KB
/
Copy pathLabyrinth.java
File metadata and controls
74 lines (66 loc) · 2.12 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
import java.util.Random;
public class Labyrinth{
private int[][] lab;
private int arraySize;
public Labyrinth(int arraySize) {
Random rand = new Random();
this.arraySize=arraySize;
int max = 4;
lab = new int[arraySize][arraySize];
for(int i= 0; i<arraySize ;i++){
for(int j= 0; j<arraySize ;j++){
//Random number from 0.0-1.0
float p=rand.nextFloat();
//Random number from 0-3 adding 1 is random number from 1-4
int value = rand.nextInt(max)+1;
if(p<=0.1){
lab[i][j]=-1;
}
else{
lab[i][j]=value;
}
}
}
}
public void printLabyrinth(int x , int y , int x1 , int y1, int x2 , int y2){
for(int i= 0; i<arraySize ;i++){
for(int j= 0; j<arraySize ;j++){
if(i==x && j==y){
System.out.print("{S "+lab[i][j]+"} ,");
}
else if(i==x1 && j==y1){
System.out.print("{G1 "+lab[i][j]+ "} ,");
}
else if(i==x2 && j==y2){
System.out.print("{G2 "+lab[i][j]+ "} ,");
}
else if(lab[i][j]==-1){
System.out.print("{---} ,");
}
else{
System.out.print("{"+lab[i][j]+ "} ,");
}
}
System.out.print("\n");
}
}
public void printLabyrinth(){
for(int i= 0; i<arraySize ;i++){
for(int j= 0; j<arraySize ;j++){
if(lab[i][j]==-1){
System.out.print("{---} ,");
}
else{
System.out.print("{"+lab[i][j]+ "} ,");
}
}
System.out.print("\n");
}
}
public int getValue(int x,int y){
return lab[x][y];
}
public int getArraySize() {
return arraySize;
}
}