diff --git a/source/Jeu.ts b/source/Jeu.ts index e43a10d..cc9545f 100644 --- a/source/Jeu.ts +++ b/source/Jeu.ts @@ -10,8 +10,14 @@ class Jeu extends Scene { public wall_ : Sprite; public pas_ : number; public rat_ : Rat; - public noisette_ : Sprite; - public pastilles_ : Array>; + public fromage_ : Sprite; + public fraise_ : Sprite; + public arriverx_ : number; + public arrivery_ : number; + public compteurfromage_ : number; + public compteurfraise_ : number; + public mangerfromage_ : Array>; + public mangerfraise_ : Array>; @@ -20,47 +26,42 @@ class Jeu extends Scene { super(element,false); /* Ecrire ici le code qui initialise la scene. */ this.pas_ = 32; - this.pastilles_ = []; + this.mangerfromage_ = []; + this.mangerfraise_ = []; } private initialiserCarte(){ - // this.carte_ = []; - // this.carte_[0] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1]; - // this.carte_[1] = [1 ,3 ,2 ,2 ,2 ,1 ,3 ,2 ,2 ,1]; - // this.carte_[2] = [1 ,1 ,2 ,1 ,1 ,1 ,2 ,1 ,2 ,1]; - // this.carte_[3] = [1 ,2 ,2 ,2 ,1 ,1 ,2 ,1 ,1 ,1]; - // this.carte_[4] = [1 ,2 ,1 ,1 ,2 ,2 ,2 ,1 ,2 ,9]; - // this.carte_[5] = [1 ,2 ,2 ,2 ,2 ,1 ,2 ,1 ,2 ,1]; - // this.carte_[6] = [1 ,2 ,1 ,8 ,1 ,1 ,2 ,2 ,2 ,1]; - // this.carte_[7] = [1 ,2 ,1 ,2 ,1 ,1 ,2 ,1 ,1 ,1]; - // this.carte_[8] = [1 ,2 ,2 ,2 ,1 ,2 ,2 ,2 ,2 ,1]; - // this.carte_[9] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1]; this.carte_ = []; this.carte_[0] = [1 ,1 ,1 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ]; this.carte_[1] = [1 ,8 ,1 ,0 ,0 ,1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 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ]; - - - } -private dessinerLabyrinthe(){ +public dessinerLabyrinthe(){ + this.compteurfromage_ = 0; + this.compteurfraise_ = 0; for(let i = 0 ; i(resolve => setTimeout(resolve, 20)); } } @@ -28,6 +30,7 @@ class Rat extends Sprite { this.py_ = this.py_+1; this.setXY(this.getX(),this.getY()+this.scene_.pas_); this.getElement().style.transform = 'rotate(90deg)'; + this.manger(); await new Promise(resolve => setTimeout(resolve, 20)); } } @@ -36,6 +39,7 @@ class Rat extends Sprite { this.px_ = this.px_-1; this.setXY(this.getX()-this.scene_.pas_,this.getY()); this.getElement().style.transform = 'rotate(90deg) scale(-1,1)'; + this.manger(); await new Promise(resolve => setTimeout(resolve, 20)); } } @@ -44,6 +48,7 @@ class Rat extends Sprite { this.px_ = this.px_+1; this.setXY(this.getX()+this.scene_.pas_,this.getY()); this.getElement().style.transform = 'rotate(90deg) scale(1,1)'; + this.manger(); await new Promise(resolve => setTimeout(resolve, 20)); } } @@ -65,6 +70,20 @@ class Rat extends Sprite { } + public manger(){ + if(this.scene_.carte_[this.py_][this.px_] == 2 || this.scene_.carte_[this.py_][this.px_] == 4 + || this.scene_.carte_[this.py_][this.px_] == 9 ){ + this.scene_.retirerFromage(this.py_,this.px_); + console.log("j'ai mange"); + this.scene_.carte_[this.py_][this.px_] = 8; + }else if(this.scene_.carte_[this.py_][this.px_] == 3){ + this.scene_.retirerFraise(this.py_,this.px_); + console.log("j'ai mange"); + this.scene_.carte_[this.py_][this.px_] = 8; + } + this.scene_.dessinerLabyrinthe(); + } + public animer(){ window.addEventListener("keydown", this.ecouteurDeplacer); } @@ -74,6 +93,6 @@ class Rat extends Sprite { } public estArriver(){ - return this.scene_.carte_[this.py_][this.px_] == 9; + return this.scene_.carte_[this.scene_.arrivery_][this.scene_.arriverx_] == 8; } } \ No newline at end of file