-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLivingCreuture.js
More file actions
33 lines (30 loc) · 925 Bytes
/
LivingCreuture.js
File metadata and controls
33 lines (30 loc) · 925 Bytes
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
module.exports = class LivingCreuture {
constructor(x, y) {
this.x = x;
this.y = y;
this.energy = 0;
this.directions = [
[this.x - 1, this.y - 1],
[this.x, this.y - 1],
[this.x + 1, this.y - 1],
[this.x - 1, this.y],
[this.x + 1, this.y],
[this.x - 1, this.y + 1],
[this.x, this.y + 1],
[this.x + 1, this.y + 1]
];
}
chooseCell(char) {
let arr = [];
for (let index = 0; index < this.directions.length; index++) {
let x = this.directions[index][0];
let y = this.directions[index][1];
if (x >= 0 && y >= 0 && x < matrix[0].length && y < matrix.length) {
if (matrix[y][x] == char) {
arr.push(this.directions[index])
}
}
}
return arr;
}
}