-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouseGenerator.java
More file actions
237 lines (197 loc) · 5.84 KB
/
HouseGenerator.java
File metadata and controls
237 lines (197 loc) · 5.84 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package model;
import java.util.ArrayList;
import java.util.List;
import game.Xform;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.control.ListCell;
import javafx.scene.image.Image;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
public class HouseGenerator extends Group
{
final double TILE_SIZE = 50;
private int NUM_TILES = 50;
public boolean visited;
public Box north; //1
public Box east; //2
public Box west; //3
public Box south;//4
public ArrayList<Box> wallList = new ArrayList<Box>();
public Box[][] wall = new Box[NUM_TILES][NUM_TILES];
public Box[][] tempWall = new Box[NUM_TILES][NUM_TILES];
public Box floor ;
public Box ceeling;
public float wallLength = 3.0f;
private Point3D initialPos;
public Xform wallXform = new Xform();
public Xform wallYform = new Xform();
public Xform floorXform = new Xform();
public Xform ceelingXform = new Xform();
public Xform houseXform = new Xform();
private Cell cells;
private int currentCell = 0;
private int totalCells;
private int visitedCells = 0;
private boolean startedBuilding = false;
private int currentNeighbor = 0;
private List<Integer> lastCells;
private int backingUp = 0;
private int wallToBreak = 0;
public class Cell
{
public Box north; //1
public Box east; //2
public Box west; //3
public Box south;//4
public Box[][] horizontals = new Box[NUM_TILES][NUM_TILES];
public Box[][] verticals = new Box[NUM_TILES][NUM_TILES];
public boolean visited[][] = new boolean [NUM_TILES][NUM_TILES];;
}
public HouseGenerator(int N)
{
this.NUM_TILES = N;
CreateWalls();
}
private void CreateWalls()
{
Image textureImage = new Image(getClass().getResourceAsStream("Wall.jpg"));
PhongMaterial material = new PhongMaterial();
material.setDiffuseMap(textureImage);
initialPos = new Point3D((-NUM_TILES / 2) + wallLength / 2, 20.3f,
(-NUM_TILES / 2) + wallLength / 2);
double initialPosX = (-NUM_TILES / 2) + wallLength / 2;
double initialPosY = 20.3f;
double initialPosZ = (-NUM_TILES / 2) + wallLength / 2;
Point3D myPos = initialPos;
for (int i = 0; i < NUM_TILES; i++)
{
for(int j =0 ; j < NUM_TILES; j++)
{
int horizontalX = i;
int verticalZ = j - 1;
wall[i][j] = new Box((horizontalX - i + 1) * TILE_SIZE, TILE_SIZE * 4,TILE_SIZE);
tempWall[i][j] = new Box(TILE_SIZE, TILE_SIZE * 4,TILE_SIZE);
wall[i][j].setMaterial(material);
tempWall[i][j].setMaterial(material);
}
//wallXform.getChildren().add(wall[i]);
//wallXform.setTranslateY(-20);
}
// For x-Axis
for (int i = 0; i < NUM_TILES; i++)
{
for (int j = 0; j < NUM_TILES; j++)
{
myPos = new Point3D(
initialPos.getX() + (j * wallLength) - wallLength / 2, 20.3f,
initialPos.getZ() + (i * wallLength) - wallLength / 2);
wall[i][j].setTranslateX((initialPosX + (j * wallLength) - wallLength / 2) * TILE_SIZE);
wall[i][j].setTranslateY(initialPosY);
wall[i][j].setTranslateZ((initialPosZ + (i * wallLength) - wallLength / 2) * TILE_SIZE);
tempWall[i][j].setTranslateX((initialPosX + (j * wallLength)) * TILE_SIZE);
tempWall[i][j].setTranslateY(initialPosY);
tempWall[i][j].setTranslateZ((initialPosZ + (i * wallLength) - wallLength) * TILE_SIZE);
wallList.add(wall[i][j]);
wallList.add(tempWall[i][j]);
}
}
// For y-Axis
/*for (int i = 0; i < ySize; i++)
{
for (int j = 0; j < xSize; j++)
{
tempWall[j][i].setTranslateX((initialPosX + (j * wallLength)) * TITLE_SIZE);
tempWall[j][i].setTranslateY(initialPosY);
tempWall[j][i].setTranslateZ((initialPosZ + (i * wallLength) - wallLength) * TITLE_SIZE);
}
}*/
//AddFloorAndCeeling();
//FinishHouse();
CreateCell();
}
private void CreateCell()
{
cells = new Cell();
for(int i = 0; i < NUM_TILES; i++)
{
for(int j = 0; j < NUM_TILES; j++)
{
cells.horizontals[i][j] = wall[i][j];
cells.verticals[i][j] = tempWall[i][j];
}
}
//FinishHouse();
CreateMaze();
}
private void CreateMaze()
{
if(visitedCells < totalCells)
{
if(startedBuilding)
{
//GetNeighbors();
for(int i =0; i < NUM_TILES; i++)
{
for(int j =0; j < NUM_TILES; j++)
{
if(cells.visited[i][j]==false)
{
BreakWall();
visitedCells++;
}
}
}
}
}
FinishHouse();
}
private void BreakWall()
{
for(int i =0; i < NUM_TILES; i++)
{
for(int j =0; j < NUM_TILES; j++)
{
switch(wallToBreak)
{
case 1: //north
{
cells.horizontals[i-1][j]= null;
}
case 2: //east
{
cells.verticals[i][j+1]= null;
}
case 3: //west
{
cells.verticals[i][j-1]= null;
}
case 4: //south
{
cells.horizontals[i+1][j]= null;
}
}
}
}
}
private void GetNeighbors()
{
}
private void FinishHouse()
{
for (int i = 0; i < NUM_TILES; i++)
{
for(int j = 0; j < NUM_TILES; j++)
{
wallXform.getChildren().add(cells.horizontals[i][j]);
wallYform.getChildren().add(cells.verticals[i][j]);
//wallXform.setTranslateZ(300);
//wallYform.setTranslateZ(TITLE_SIZE);
//wallYform.setRotateY(90);
wallXform.setTranslateY(-20);
wallYform.setTranslateY(-20);
}
}
houseXform.getChildren().addAll(wallXform, wallYform);
}
}