-
Notifications
You must be signed in to change notification settings - Fork 0
/
caveGen.js
59 lines (44 loc) · 1.46 KB
/
caveGen.js
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
// CaveGen test.
var caveTiles = function(width, height) {
this.cwidth = width;
this.cheight = height;
this.wallCount = 0;
this.floorCount = 0;
var tile;
this.map = [];
for (var i =0; i <= this.cwidth; i++) {
tile = Math.round(Math.random(-1,1));
this.map.push([]);
for (var j = 0; j <= this.cheight; j++)
{
tile = Math.round(Math.random(-1,1));
if (tile === 1) { tile = '#';} else {tile = ' ';}
if (tile === '#') {this.wallCount++;} else {this.floorCount++;}
this.map[i].push(tile);
// console.log(tile);
}
// console.log(tile);
}
this.printMap = function() {
for (var i in this.map) {console.log(this.map[i].join(""));}
};
this.smoothMap = function(times) {
// First get a list of tiles to change THEN perform the change after all changes are determined.
this.changeList = [];
var floor = 0; var wall = 0;
for (var row in this.map) {
for (var column in this.map[row]) {
for (var x = -1; x < 2; x ++) {
for (var y = -1; y < 2; y++) {
console.log("x: "+x+" , y: "+y);
}
}
if (this.map[row][column] === '#') {wall++;} // If row +/- 1 out of bounds ( 0<x<width), don't try to check it
// console.log("row: "+row+ " column: "+column); // If column +/- 1 out of bounds ( 0 < y < height), don't try to check it.
}
}
};
};
var smallCave = new caveTiles(10,10);
var board = document.getElementsByClassName("cave");
board.innerHTML = ("<p>shite</p>");