-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGishatich.js
executable file
·128 lines (116 loc) · 4 KB
/
Gishatich.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
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
class Gishatich extends KendaniEak {
constructor(x, y, index) {
super(x, y, index);
this.directions = [];
this.bazmanaluAragutyun;
this.energy = 50;
this.zuyg;
}
yntrelVandak(ch, ch1, ch2, ch3, ch4) {
this.stanalNorKordinatner();
return super.yntrelVandak(ch, ch1, ch2, ch3, ch4);
}
stanalNorKordinatner() {
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]
];
}
stanalExanak(exanak) {
if (exanak == "spring") {
this.bazmanaluAragutyun = 50;
} else if (exanak == 'summer') {
this.bazmanaluAragutyun = 55;
} else if (exanak == "autumn") {
this.bazmanaluAragutyun = 57;
}
}
utel() {
this.stanalNorKordinatner();
var vandak = random(this.yntrelVandak(0, 1, 2));
if (vandak && matrix[vandak[1]][vandak[0]] == 2) {
matrix[this.y][this.x] = 0;
this.x = vandak[0];
this.y = vandak[1];
matrix[this.y][this.x] = this.index;
for (var c in xotakernerArr) {
if (this.x == xotakernerArr[c].x && this.y == xotakernerArr[c].y) {
xotakernerArr.splice(c, 1);
GishKoghmicSpanvacXotaker++;
this.energy++;
break;
}
}
} else if (vandak && matrix[vandak[1]][vandak[0]] == 1) {
matrix[this.y][this.x] = 1;
this.x = vandak[0];
this.y = vandak[1];
matrix[this.y][this.x] = this.index;
this.energy--;
} else if (vandak && matrix[vandak[1]][vandak[0]] == 0) {
matrix[this.y][this.x] = 0;
this.x = vandak[0];
this.y = vandak[1];
matrix[this.y][this.x] = this.index;
this.energy--;
}
}
gtnelZuyg() {
if (this.ser == 1) {
this.zuyg = 0;
} else {
this.zuyg = 1;
}
}
bazmanal() {
this.stanalNorKordinatner();
var vandakZ = random(this.yntrelVandak(3));
for (var i in gishatichnerArr) {
if (vandakZ && vandakZ[0] == gishatichnerArr[i].x && vandakZ[1] == gishatichnerArr[i].y) {
var zuygiIndex = i;
break;
}
}
if (zuygiIndex && this.energy >= this.bazmanaluAragutyun && gishatichnerArr[zuygiIndex].ser == this.zuyg) {
var vandak = random(this.yntrelVandak(0, 1, 2));
var norGishatich = new Gishatich(vandak[0], vandak[1], 3);
gishatichnerArr.push(norGishatich);
if (matrix[vandak[1]][vandak[0]] == 1) {
for (var c in grassArr) {
if (vandak[0] == grassArr[c].x && vandak[1] == grassArr[c].y) {
grassArr.splice(c, 1);
break;
}
}
} else if (matrix[vandak[1]][vandak[0]] == 2) {
for (var c in xotakernerArr) {
if (vandak[0] == xotakernerArr[c].x && vandak[1] == xotakernerArr[c].y) {
xotakernerArr.splice(c, 1);
GishKoghmicSpanvacXotaker++;
break;
}
}
}
matrix[vandak[1]][vandak[0]] = 3;
this.energy = 45;
}
}
mahanal() {
if (this.energy <= 0) {
matrix[this.y][this.x] = 0;
for (var s in gishatichnerArr) {
if (this.x == gishatichnerArr[s].x && this.y == gishatichnerArr[s].y) {
gishatichnerArr.splice(s, 1);
spanvacGishatichner++;
break;
}
}
}
}
}