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 -->
<!-- <div id="fullscreen" onmousedown="scene.toggleFullscreen(event);">F</div> -->
</div>
<div>
<div id="compteurfraise">oui</div>
<div id="compteurfromage">oui</div>
</div>
</body>
</html>

@ -16,8 +16,12 @@ class Jeu extends Scene {
public arrivery_ : number;
public compteurfromage_ : number;
public compteurfraise_ : number;
public totalfraise_ : number;
public totalfromage_ : number;
public mangerfromage_ : 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.mangerfromage_ = [];
this.mangerfraise_ = [];
this.compteurfromagemoins_ = 0;
this.compteurfraisemoins_ = 0;
}
@ -60,7 +66,6 @@ public dessinerLabyrinthe(){
if (this.carte_[i][j] == 9){
this.arriverx_ = j;
this.arrivery_ = i;
// console.log(this.arriverx_,this.arrivery_);
}
if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img"));
@ -89,13 +94,11 @@ public dessinerLabyrinthe(){
}
if(this.carte_[i][j] == 2){
this.mangerfromage_[i][j] = this.fromage_;
this.compteurfromage_++;
} else {
this.mangerfromage_[i][j] = null;
}
if(this.carte_[i][j] == 3){
this.mangerfraise_[i][j] = this.fraise_;
this.compteurfraise_++;
} else {
this.mangerfraise_[i][j] = null;
}
@ -104,8 +107,6 @@ public dessinerLabyrinthe(){
console.log(this.mangerfromage_);
console.log(this.mangerfraise_);
console.log(this.carte_);
console.log(this.compteurfraise_);
console.log(this.compteurfromage_);
}
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++){
if (this.carte_[i][j] == 8){
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++){
if (this.carte_[i][j] == 8){
this.carte_[i][j] = 4;
this.compteurfraisemoins_++;
this.compteurfraise_ = this.totalfraise_ - this.compteurfraisemoins_;
console.log(this.compteurfraise_);
}
}
}
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() {
const scene = document.getElementById('scene')
while (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
public override start() {
/* Ecrire ici le code qui demarre la scene. */
console.log(this.carte_);
this.initialiserCarte();
this.dessinerLabyrinthe();
this.compteur();
this.rat_.animer();
this.rat_.estArriver();
}

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

Loading…
Cancel
Save