back integrer rajoue de niveau WIP

master
Victor BRUN 2 years ago
parent d744b5ae39
commit c95360ef1a

@ -22,6 +22,8 @@ class Jeu extends Scene {
public mangerfraise_ : Array<Array<Sprite>>; public mangerfraise_ : Array<Array<Sprite>>;
public compteurfromagemoins_ : number; public compteurfromagemoins_ : number;
public compteurfraisemoins_ : number; public compteurfraisemoins_ : number;
public niveau_ : any;
private idniveau_ : number;
@ -34,29 +36,48 @@ class Jeu extends Scene {
this.mangerfraise_ = []; this.mangerfraise_ = [];
this.compteurfromagemoins_ = 0; this.compteurfromagemoins_ = 0;
this.compteurfraisemoins_ = 0; this.compteurfraisemoins_ = 0;
} this.idniveau_ = 1;
}
private initialiserCarte(){ private telechargerNiveau(id : number){
this.carte_ = []; let requete : XMLHttpRequest = new XMLHttpRequest();
this.carte_[0] = [1 ,1 ,1 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ]; let parametres : string = "id=" + id;
this.carte_[1] = [1 ,8 ,1 ,0 ,0 ,1 ,2 ,2 ,2 ,2 ,2 ,1 ,0 ,1 ,2 ,2 ,2 ,1 ,0 ,0 ]; requete.open("get", "http://localhost/SAE/index.php?" + parametres);
this.carte_[2] = [1 ,2 ,1 ,0 ,0 ,1 ,2 ,4 ,4 ,4 ,2 ,1 ,0 ,1 ,2 ,1 ,2 ,1 ,1 ,0 ]; /* Ecouteur déclenché à la réception des données */
this.carte_[3] = [1 ,2 ,1 ,0 ,0 ,1 ,2 ,1 ,1 ,1 ,2 ,1 ,0 ,1 ,2 ,3 ,2 ,2 ,1 ,0 ]; requete.onreadystatechange = () => {
this.carte_[4] = [1 ,2 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,1 ,2 ,1 ,0 ,1 ,2 ,1 ,4 ,2 ,1 ,0 ]; if (requete.readyState == XMLHttpRequest.DONE
this.carte_[5] = [1 ,2 ,2 ,2 ,1 ,3 ,2 ,1 ,2 ,1 ,2 ,1 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2 ,2 ,2 ,2 ,2 ,1 ,4 ,2 ,1 ,1 ];
// this.carte_[12] = [1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 ,2 ,1 ,1 ,2 ,1 ,2 ,1 ,1 ,1 ,2 ,9 ,1 ];
// this.carte_[13] = [0 ,0 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,1 ,1 ,3 ,2 ,2 ,1 ,0 ,1 ,1 ,1 ,1 ];
// this.carte_[14] = [0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ];
this.carte_ = JSON.parse(this.niveau_.niveau);
}
public dessinerLabyrinthe(){
this.compteurfromage_ = 0; this.compteurfromage_ = 0;
this.compteurfraise_ = 0; this.compteurfraise_ = 0;
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
@ -107,9 +128,9 @@ 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_);
} }
public retirerFromage(y : number, x : number){ public retirerFromage(y : number, x : number){
this.carte_[y][x] = 4; this.carte_[y][x] = 4;
this.mangerfromage_[y][x] = null; this.mangerfromage_[y][x] = null;
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
@ -123,8 +144,8 @@ public retirerFromage(y : number, x : number){
} }
} }
this.removeAllChildNodes(); this.removeAllChildNodes();
} }
public retirerFraise(y : number, x : number){ public retirerFraise(y : number, x : number){
this.carte_[y][x] = 4; this.carte_[y][x] = 4;
this.mangerfraise_[y][x] = null; this.mangerfraise_[y][x] = null;
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
@ -138,9 +159,9 @@ public retirerFraise(y : number, x : number){
} }
} }
this.removeAllChildNodes(); this.removeAllChildNodes();
} }
public replacerPersonnage(ny : number, nx : number, ay : number, ax : number){ public replacerPersonnage(ny : number, nx : number, ay : number, ax : number){
this.carte_[ny][nx] = 8; this.carte_[ny][nx] = 8;
this.carte_[ay][ax] = 4; this.carte_[ay][ax] = 4;
// for(let i = 0 ; i<this.carte_.length; i++){ // for(let i = 0 ; i<this.carte_.length; i++){
@ -152,16 +173,16 @@ public replacerPersonnage(ny : number, nx : number, ay : number, ax : number){
// } // }
// } // }
this.removeAllChildNodes(); 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(){ public compteur(){
this.totalfromage_ = 0; this.totalfromage_ = 0;
this.totalfraise_ = 0; this.totalfraise_ = 0;
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
@ -176,9 +197,9 @@ public compteur(){
} }
console.log(this.totalfraise_); console.log(this.totalfraise_);
console.log(this.totalfromage_); console.log(this.totalfromage_);
} }
//--------------------------------------------------------------------------------------------start //--------------------------------------------------------------------------------------------start
public override start() { public start_suite() {
/* 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();
@ -187,6 +208,11 @@ public compteur(){
this.rat_.animer(); this.rat_.animer();
this.rat_.estArriver(); this.rat_.estArriver();
} }
public override start() {
/* Ecrire ici le code qui demarre la scene. */
this.telechargerNiveau(this.idniveau_);
this.idniveau_++;
}
//--------------------------------------------------------------------------------------------pause //--------------------------------------------------------------------------------------------pause
public override pause() { public override pause() {
@ -204,6 +230,7 @@ public compteur(){
/* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */ /* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */
} }
} }
// Fin //-------------------------------------------------------------------------------------------
// Fin //-------------------------------------------------------------------------------------------

Loading…
Cancel
Save