compteur non visible fonctionnel et WIP visible

master
Victor BRUN 1 year ago
parent d4acaba58b
commit d744b5ae39

@ -26,5 +26,10 @@
<!-- Le code ci-dessous permet affiche un bouton pour le plein ecran --> <!-- Le code ci-dessous permet affiche un bouton pour le plein ecran -->
<!-- <div id="fullscreen" onmousedown="scene.toggleFullscreen(event);">F</div> --> <!-- <div id="fullscreen" onmousedown="scene.toggleFullscreen(event);">F</div> -->
</div> </div>
<div>
<div id="compteurfraise">oui</div>
<div id="compteurfromage">oui</div>
</div>
</body> </body>
</html> </html>

@ -16,8 +16,12 @@ class Jeu extends Scene {
public arrivery_ : number; public arrivery_ : number;
public compteurfromage_ : number; public compteurfromage_ : number;
public compteurfraise_ : number; public compteurfraise_ : number;
public totalfraise_ : number;
public totalfromage_ : number;
public mangerfromage_ : Array<Array<Sprite>>; public mangerfromage_ : Array<Array<Sprite>>;
public mangerfraise_ : Array<Array<Sprite>>; public mangerfraise_ : Array<Array<Sprite>>;
public compteurfromagemoins_ : number;
public compteurfraisemoins_ : number;
@ -28,6 +32,8 @@ class Jeu extends Scene {
this.pas_ = 32; this.pas_ = 32;
this.mangerfromage_ = []; this.mangerfromage_ = [];
this.mangerfraise_ = []; this.mangerfraise_ = [];
this.compteurfromagemoins_ = 0;
this.compteurfraisemoins_ = 0;
} }
@ -60,7 +66,6 @@ public dessinerLabyrinthe(){
if (this.carte_[i][j] == 9){ if (this.carte_[i][j] == 9){
this.arriverx_ = j; this.arriverx_ = j;
this.arrivery_ = i; this.arrivery_ = i;
// console.log(this.arriverx_,this.arrivery_);
} }
if(this.carte_[i][j] == 1){ if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img")); this.wall_ = new Sprite(document.createElement("img"));
@ -89,13 +94,11 @@ public dessinerLabyrinthe(){
} }
if(this.carte_[i][j] == 2){ if(this.carte_[i][j] == 2){
this.mangerfromage_[i][j] = this.fromage_; this.mangerfromage_[i][j] = this.fromage_;
this.compteurfromage_++;
} else { } else {
this.mangerfromage_[i][j] = null; this.mangerfromage_[i][j] = null;
} }
if(this.carte_[i][j] == 3){ if(this.carte_[i][j] == 3){
this.mangerfraise_[i][j] = this.fraise_; this.mangerfraise_[i][j] = this.fraise_;
this.compteurfraise_++;
} else { } else {
this.mangerfraise_[i][j] = null; this.mangerfraise_[i][j] = null;
} }
@ -104,8 +107,6 @@ public dessinerLabyrinthe(){
console.log(this.mangerfromage_); console.log(this.mangerfromage_);
console.log(this.mangerfraise_); console.log(this.mangerfraise_);
console.log(this.carte_); console.log(this.carte_);
console.log(this.compteurfraise_);
console.log(this.compteurfromage_);
} }
public retirerFromage(y : number, x : number){ public retirerFromage(y : number, x : number){
@ -115,6 +116,9 @@ public retirerFromage(y : number, x : number){
for(let j = 0 ; j<this.carte_[i].length; j++){ for(let j = 0 ; j<this.carte_[i].length; j++){
if (this.carte_[i][j] == 8){ if (this.carte_[i][j] == 8){
this.carte_[i][j] = 4; this.carte_[i][j] = 4;
this.compteurfromagemoins_++;
this.compteurfromage_ = this.totalfromage_ - this.compteurfromagemoins_;
console.log(this.compteurfromage_);
} }
} }
} }
@ -127,23 +131,59 @@ public retirerFraise(y : number, x : number){
for(let j = 0 ; j<this.carte_[i].length; j++){ for(let j = 0 ; j<this.carte_[i].length; j++){
if (this.carte_[i][j] == 8){ if (this.carte_[i][j] == 8){
this.carte_[i][j] = 4; this.carte_[i][j] = 4;
this.compteurfraisemoins_++;
this.compteurfraise_ = this.totalfraise_ - this.compteurfraisemoins_;
console.log(this.compteurfraise_);
} }
} }
} }
this.removeAllChildNodes(); this.removeAllChildNodes();
} }
public replacerPersonnage(ny : number, nx : number, ay : number, ax : number){
this.carte_[ny][nx] = 8;
this.carte_[ay][ax] = 4;
// for(let i = 0 ; i<this.carte_.length; i++){
// for(let j = 0 ; j<this.carte_[i].length; j++){
// if (this.carte_[i][j] == 8){
// this.carte_[i][j] = 4;
// console.log("j'ai bouger");
// }
// }
// }
this.removeAllChildNodes();
}
public removeAllChildNodes() { public removeAllChildNodes() {
const scene = document.getElementById('scene') const scene = document.getElementById('scene')
while (scene.firstChild) { while (scene.firstChild) {
scene.removeChild(scene.firstChild); scene.removeChild(scene.firstChild);
} }
} }
public compteur(){
this.totalfromage_ = 0;
this.totalfraise_ = 0;
for(let i = 0 ; i<this.carte_.length; i++){
for(let j = 0 ; j<this.carte_[i].length; j++){
if(this.carte_[i][j] == 2){
this.totalfromage_++;
}
if(this.carte_[i][j] == 3){
this.totalfraise_++;
}
}
}
console.log(this.totalfraise_);
console.log(this.totalfromage_);
}
//--------------------------------------------------------------------------------------------start //--------------------------------------------------------------------------------------------start
public override start() { public override start() {
/* Ecrire ici le code qui demarre la scene. */ /* Ecrire ici le code qui demarre la scene. */
console.log(this.carte_); console.log(this.carte_);
this.initialiserCarte(); this.initialiserCarte();
this.dessinerLabyrinthe(); this.dessinerLabyrinthe();
this.compteur();
this.rat_.animer(); this.rat_.animer();
this.rat_.estArriver(); this.rat_.estArriver();
} }

@ -5,6 +5,8 @@ class Rat extends Sprite {
private ecouteurDeplacer : any; private ecouteurDeplacer : any;
public px_ : number; public px_ : number;
public py_ : number; public py_ : number;
public ancienpx_ : number;
public ancienpy_ : number;
//Constructeur //Constructeur
public constructor(scene : Jeu,element : HTMLElement, py : number, px : number){ public constructor(scene : Jeu,element : HTMLElement, py : number, px : number){
super(element); super(element);
@ -17,6 +19,8 @@ class Rat extends Sprite {
async haut(){ async haut(){
while(this.scene_.carte_[this.py_-1][this.px_] != 1){ while(this.scene_.carte_[this.py_-1][this.px_] != 1){
this.ancienpy_ = this.py_;
this.ancienpx_ = this.px_;
this.py_ = this.py_-1; this.py_ = this.py_-1;
this.setXY(this.getX(),this.getY()-this.scene_.pas_); this.setXY(this.getX(),this.getY()-this.scene_.pas_);
this.getElement().style.transform = 'rotate(-90deg)'; this.getElement().style.transform = 'rotate(-90deg)';
@ -27,6 +31,8 @@ class Rat extends Sprite {
} }
async bas(){ async bas(){
while(this.scene_.carte_[this.py_+1][this.px_] != 1){ while(this.scene_.carte_[this.py_+1][this.px_] != 1){
this.ancienpy_ = this.py_;
this.ancienpx_ = this.px_;
this.py_ = this.py_+1; this.py_ = this.py_+1;
this.setXY(this.getX(),this.getY()+this.scene_.pas_); this.setXY(this.getX(),this.getY()+this.scene_.pas_);
this.getElement().style.transform = 'rotate(90deg)'; this.getElement().style.transform = 'rotate(90deg)';
@ -36,6 +42,8 @@ class Rat extends Sprite {
} }
async gauche(){ async gauche(){
while(this.scene_.carte_[this.py_][this.px_-1] != 1){ while(this.scene_.carte_[this.py_][this.px_-1] != 1){
this.ancienpy_ = this.py_;
this.ancienpx_ = this.px_;
this.px_ = this.px_-1; this.px_ = this.px_-1;
this.setXY(this.getX()-this.scene_.pas_,this.getY()); this.setXY(this.getX()-this.scene_.pas_,this.getY());
this.getElement().style.transform = 'rotate(90deg) scale(-1,1)'; this.getElement().style.transform = 'rotate(90deg) scale(-1,1)';
@ -45,6 +53,8 @@ class Rat extends Sprite {
} }
async droite(){ async droite(){
while(this.scene_.carte_[this.py_][this.px_+1] != 1){ while(this.scene_.carte_[this.py_][this.px_+1] != 1){
this.ancienpy_ = this.py_;
this.ancienpx_ = this.px_;
this.px_ = this.px_+1; this.px_ = this.px_+1;
this.setXY(this.getX()+this.scene_.pas_,this.getY()); this.setXY(this.getX()+this.scene_.pas_,this.getY());
this.getElement().style.transform = 'rotate(90deg) scale(1,1)'; this.getElement().style.transform = 'rotate(90deg) scale(1,1)';
@ -71,8 +81,10 @@ class Rat extends Sprite {
} }
public manger(){ public manger(){
if(this.scene_.carte_[this.py_][this.px_] == 2 || this.scene_.carte_[this.py_][this.px_] == 4 if(this.scene_.carte_[this.py_][this.px_] == 4 || this.scene_.carte_[this.py_][this.px_] == 9 ){
|| this.scene_.carte_[this.py_][this.px_] == 9 ){ this.scene_.replacerPersonnage(this.py_,this.px_,this.ancienpy_,this.ancienpx_);
console.log("j'ai bouger");
}else if(this.scene_.carte_[this.py_][this.px_] == 2){
this.scene_.retirerFromage(this.py_,this.px_); this.scene_.retirerFromage(this.py_,this.px_);
console.log("j'ai mange"); console.log("j'ai mange");
this.scene_.carte_[this.py_][this.px_] = 8; this.scene_.carte_[this.py_][this.px_] = 8;

Loading…
Cancel
Save