-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocation.java
75 lines (69 loc) · 2.45 KB
/
Location.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
import java.util.ArrayList;
import java.util.Random;
public class Location {
static ArrayList<ArrayList<Integer>> Locations = new ArrayList<ArrayList<Integer>>(); // ArrayList for all locations for Monsters and Trees
static int[][] WarriorLocations = new int[4][2]; // Warrior Locations
static int[][] TreesandMonsterLocation = new int[10][2]; // Trees and Monster Locations
public static int[][] makeTreesandMonsterLocation(){ // method for make Locations for Monsters and Trees
for (int i=0; i<10; i++){
int[] loc = setLocation();
TreesandMonsterLocation[i] = loc;
}
return TreesandMonsterLocation;
}
public static int[] setLocation() { // Set the Locations for a unique object
boolean occupied = true;
ArrayList<Integer> newLocation = new ArrayList<Integer>(2);
ArrayList<Integer> mountdome = new ArrayList<Integer>(2);
mountdome.add(5);
mountdome.add(5);
while (occupied) { // if the location is occupied by someone
occupied = false;
newLocation.clear();
Random r = new Random();
newLocation.add(r.nextInt(10));
newLocation.add(r.nextInt(10));
if (newLocation.equals(mountdome)) {
occupied = true;
}
for (int i = 0; i < Locations.size(); i++) {
if (Locations.get(i).equals(newLocation)) {
occupied = true;
break;
}
}
}
Locations.add(newLocation);
int arry[] = new int[2];
arry[0] = newLocation.get(0);
arry[1] = newLocation.get(1);
return arry;
}
public static int[][] setWarriorLocations() { // set the warrior Locations Randomly
Random randomwarr = new Random();
for (int i= 0; i < 4; i++) {
int[] subLocation = new int[2];
int randomloc = randomwarr.nextInt(4);
switch(randomloc){
case 0 :
subLocation[0]= randomwarr.nextInt(11);
subLocation[1]= 0;
break;
case 1 :
subLocation[0]= 0;
subLocation[1]= randomwarr.nextInt(11);
break;
case 2 :
subLocation[0]= 10;
subLocation[1]= randomwarr.nextInt(11);
break;
case 3 :
subLocation[0]= randomwarr.nextInt(11);
subLocation[1]= 10;
break;
}
WarriorLocations[i]= subLocation;
}
return WarriorLocations;
}
}