class Mause {
constructor(x, y) {
this.x = x;
this.y = y;
this.life = 5;
this.directions = [];
}
getNewcordinates(){
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(character) {
this.getNewcordinates();
var found = [];
for (var i in this.directions) {
var x = this.directions[i][0];
var y = this.directions[i][1];
if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {
if (matrix[y][x] == character) {
found.push(this.directions[i]);
}
}
}
return found;
}
mul() {
let emptyCells = this.chooseCell(0);
let newCell = random(emptyCells);
if (newCell) {
let x = newCell[0];
let y = newCell[1];
// matrixi mej gru mem MEK ->
matrix[y][x] = 2;
let a = new Mause(x, y);
fishArr.push(a);
this.life = 0;
}
}
eat() {
let emptyCells = this.chooseCell(1);
let newCell = random(emptyCells);
if (newCell) {
this.life++;
let x = newCell[0];
let y = newCell[1];
matrix[y][x] = 2;
matrix[this.y][this.x] = 0;
for (let i in fishArr) {
if (fishArr[i].x == x && fishArr[i].y == y) {
fishArr.splice(i, 1)
}
}
this.x = x;
this.y = y;
if (this.life >= 10) {
this.mul();
}
} else {
this.move()
}
}
move() {
this.life--;
let emptyCells = this.chooseCell(0);
let newCell = random(emptyCells);
if (newCell) {
let x = newCell[0];
let y = newCell[1];
// matrixi mej gru mem MEK -> 1
matrix[y][x] = 2;
matrix[this.y][this.x] = 0;
this.y = y;
this.x = x;
}
if (this.life < 0) {
this.die();
}
}
die() {
matrix[this.y][this.x] = 0;
for (let i in fishArr) {
if (fishArr[i].x == this.x && fishArr[i].y == this.y) {
fishArr.splice(i, 1)
}
}
}
}
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Имеется массив объектов ценУ каждого объекта цены есть её значение и условие применения, которое зависит от количество заказанных продуктов...
Хочу использовать вебсокеты для получения курса валют с биржи битфинексНо в браузере получаю ошибку