-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.js
More file actions
137 lines (124 loc) · 3.81 KB
/
Monster.js
File metadata and controls
137 lines (124 loc) · 3.81 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var LivingCreuture = require("./LivingCreuture.js")
module.exports = class Monster extends LivingCreuture {
constructor(x, y) {
super(x, y)
this.energy = 5;
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],
[this.x - 2, this.y - 2],
[this.x, this.y - 2],
[this.x + 2, this.y - 2],
[this.x - 2, this.y],
[this.x + 2, this.y],
[this.x - 2, this.y + 2],
[this.x, this.y + 2],
[this.x + 2, this.y + 2]
];
}
//vorpes method
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],
[this.x - 2, this.y - 2],
[this.x, this.y - 2],
[this.x + 2, this.y - 2],
[this.x - 2, this.y],
[this.x + 2, this.y],
[this.x - 2, this.y + 2],
[this.x, this.y + 2],
[this.x + 2, this.y + 2]
];
}
//qayluma
move() {
this.energy--;
let chooseCells = this.chooseCell(0);
let newCell = chooseCells[Math.floor(Math.random() * chooseCells.length)];
if (newCell) {
let x = newCell[0];
let y = newCell[1];
matrix[y][x] = 2;
matrix[this.y][this.x] = 0;
this.y = y;
this.x = x;
}
if (newCell && this.energy < 0) {
this.die();
}
if (this.energy < 0) {
this.die();
}
}
eat() {
this.getNewCoordinates();
let chooseCells = this.chooseCell(4);
let newCell = chooseCells[Math.floor(Math.random() * chooseCells.length)]
if (newCell) {
this.energy += 20;
let x = newCell[0];
let y = newCell[1];
matrix[y][x] = 5;
matrix[this.y][this.x] = 0;
this.y = y;
this.x = x;
for (let index = 0; index < changerArr.length; index++) {
if (changerArr[index].x == x && changerArr[index].y == y) {
changerArr.splice(index, 1)
}
}
if (weather == "Spring") {
if (this.energy > 60) {
this.mul()
}
}
else if (weather == "Summer") {
if (this.energy > 40) {
this.mul()
}
}
else if (weather == "Winter") {
if (this.energy > 90) {
this.mul()
}
}
else if (weather == "Autumn") {
if (this.energy > 30) {
this.mul()
}
}
}
else { this.move() }
}
mul() {
let chooseCells = this.chooseCell(0);
let newCell = chooseCells[Math.floor(Math.random() * chooseCells.length)]
if (this.energy >= 8 && newCell) {
var newmonsterArr = new Monster(newCell[0], newCell[1]);
monsterArr.push(newmonsterArr);
matrix[newCell[1]][newCell[0]] = 5;
this.energy = 5;
}
}
die() {
matrix[this.y][this.x] = 0;
for (var i in monsterArr) {
if (monsterArr[i].y == this.y && monsterArr[i].x == this.x) {
monsterArr.splice(i, 1);
}
}
}
}