This repository has been archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.java
54 lines (49 loc) · 1.65 KB
/
Board.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
import java.io.Serializable;
import java.util.ArrayList;
public class Board implements Serializable{
private static final long serialVersionUID = 1L;
public int boardLength;
public Tile[][] Board;
public Board(int length) {
this.boardLength = length;
Board = new Tile[length][length];
for(int i = 0; i < length; i++){
for(int j = 0; j < length; j++){
Board[i][j] = null;
}
}
int xCoord;
int yCoord;
int squareLength;
Biome biome = Biome.naturalBiomes[(int) (Math.random() * Biome.naturalBiomes.length)];
ArrayList<Biome> touching = new ArrayList<Biome>();
long amtNulls = length * length;
do{
xCoord = (int) (Math.random() * length);
yCoord = (int) (Math.random() * length);
squareLength = (int) (0.01 * (length + 1) * Math.random());
touching.clear();
for(int i = -1; i <= squareLength; i++){
for(int j = -1; j <= squareLength; j++){
if(xCoord + i >= 0 && yCoord + j >= 0 && xCoord + i < length && yCoord + j < length && Board[xCoord + i][yCoord + j] != null){
touching.add(Board[xCoord + i][yCoord + j].getBiome());
}
}
}
if(touching.size() == 0){
biome = Biome.naturalBiomes[(int) (Math.random() * Biome.naturalBiomes.length)];
}else{
biome = Biome.generateSimilarBiome(touching.get((int) (Math.random() * touching.size())), Biome.naturalBiomes);
}
for(int i = 0; i < squareLength; i++){
for(int j = 0; j < squareLength; j++){
if(xCoord + i < length && yCoord + j < length && Board[xCoord + i][yCoord + j] == null){
Board[xCoord + i][yCoord + j] = new Tile(biome);
amtNulls--;
}
}
}
//System.out.println(amtNulls);
}while(amtNulls > 0);
}
}