Итак, я написал этот код.Это неправильно, я думаю.Не могли бы вы мне помочь.Я буду очень благодарен.Есть ли другие ошибки тоже?
var newCell = random (chooseCell (1));в этом штрихе у меня ошибка: ChooseCell не определено
class GrassEater{
constructor(x,y,index){
this.x = x;
this.y = y;
this.index = index;
this.energy = 5;
this.directions = [];}
getNewCoordinates(){
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.getNewCoordinates();
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;}
move() {var newCell = random(this.chooseCell(0));
if (newCell) {var newX = newCell[0];
var newY = newCell[1];
matrix[this.y][this.x] = 0;
matrix[newY][newX] = this.index;
this.y = newY;
this.x = newX;
this.energy--;}}
mul() { var newCell = random(this.chooseCell(0));
if (this.energy >= 8 && newCell) {
var animalArr = new GrassEater(newCell[0], newCell[1], this.index);
grassEaterArr.push(animalArr);
matrix[newCell[1]][newCell[0]] = 2;
this.energy = 5; }}
eat(){var newCell = random(chooseCell(1));
if(newCell) { var newX = newCell[0];
var newY = newCell[1];
matrix[this.x][this.y]= 0;
matrix[newY][newX]= this.index;
this.energy--;}
this.y= newY;
this.x= newX;
this.energy += 3 }}