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

Loading…
Cancel
Save