-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.js
50 lines (47 loc) · 1.38 KB
/
map.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
const table = require('table');
const emptyField = '';
// játéktér generálása
const generateMap = (width, height) => {
console.clear();
const arr = new Array(height);
const PosEagle = (arr.length - 1) / 2;
for (let posX = 0; posX < arr.length; posX++) {
arr[posX] = new Array(width);
}
for (let posX = 0; posX < arr.length; posX++) {
for (let posY = 0; posY < arr[posX].length; posY++) {
arr[posX][posY] = emptyField;
arr[0][posY] = 'F';
arr[arr.length - 1][posY] = 'F';
arr[posX][0] = 'F';
arr[posX][arr.length - 1] = 'F';
arr[arr.length - 2][PosEagle] = 'E';
arr[arr.length - 2][PosEagle - 1] = 'B';
arr[arr.length - 2][PosEagle + 1] = 'B';
arr[arr.length - 3][PosEagle - 1] = 'B';
arr[arr.length - 3][PosEagle + 1] = 'B';
arr[arr.length - 3][PosEagle] = 'B';
}
}
for (let posX = 2; posX < arr.length - 3; posX++) {
for (let posY = 1; posY < arr[posX].length - 1; posY++) {
if (posX % 6 !== 0 && posY % 2 === 0) {
arr[posX][posY] = 'B';
}
}
}
return arr;
};
// pálya kirajzoltatása
const printMap = (map, score, player, totalEnemies) => {
console.clear(map);
console.log(table.table(map));
console.log('Life:', player.life);
console.log('Enemies left:', 10 - totalEnemies);
console.log('Score:', score);
};
module.exports = {
emptyField,
generateMap,
printMap
};