-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-example.js
executable file
·59 lines (49 loc) · 1.09 KB
/
node-example.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
59
#!/usr/bin/env node
/**
* Visualizes level generation output using Node in the console
*/
var roguelike = require('./roguelike-level.js');
var start = new Date();
var level = roguelike({
width: 31,
height: 19,
retry: 100,
special: true,
room: {
ideal: 11,
min_width: 3,
max_width: 9,
min_height: 3,
max_height: 9
}
});
var world = level.world;
var end = new Date();
console.log(JSON.stringify(level));
// Crude mechanism for drawing level
for (var y = 0; y < world.length; y++) {
var row = '';
for (var x = 0; x < world[y].length; x++) {
var tile = world[y][x];
if (tile === 0) {
row += ' ';
} else if (tile === 1) {
row += '.';
} else if (tile === 2) {
row += '#';
} else if (tile === 3) {
row += '/';
} else if (tile === 4) {
row += 'X';
} else if (tile === 5) {
row += '<';
} else if (tile === 6) {
row += '>';
} else {
row += world[y][x];
}
}
console.log(row + '| ' + y);
}
console.log('-'.repeat(world[0].length) + '+');
console.log('TIME TOOK: ' + (end - start) + 'ms');