This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBanane.js
64 lines (44 loc) · 1.73 KB
/
Banane.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
class Banane {
constructor(propriétaire,position) {
this.propriétaire = propriétaire;
this.position = position;
this.cooldown = 0;
this.tirsRestants = 4;
}
tirer(jeu){
var joueur;//Calcul de l'état du propriétaire pour ne pas fiare de tirs alliés
for (var j of jeu.joueurs){
if (j.pseudo==this.propriétaire){
joueur = j;
}
}
if (this.tirsRestants==0){//Destruction des bananes mortes
joueur.bananes = joueur.bananes.filter((elem)=>elem!=this);
};
if (this.cooldown<1){
var distance = 3;//Même principe que lorsque les créatures cherchent leur cible
var cible;
var possiblePositions = [];
possiblePositions.push(this.position);
var besoin;
for (i=0;i<distance;i++){
var tablo = [];//pour éviter le bouclage infini
for (let element of possiblePositions){
for (let j of jeu.casesAdjacentes(element)){
if (!jeu.tanières.includes(j)&&jeu.board[j]!=0&&!joueur.creatures.includes(jeu.board[j])){
jeu.board[j].tuer(jeu);
this.cooldown = 3;
this.tirsRestants--;
return;
};
if (!tablo.includes(j)&&!jeu.tanières.includes(j))
{tablo.push(j)};
}
}
possiblePositions=tablo;
}
}
if (this.cooldown>0){this.cooldown--};
}
}
module.exports = { Banane };