back integrer rajoue de niveau WIP

master
Victor BRUN 2 years ago
parent d744b5ae39
commit c95360ef1a

@ -4,206 +4,233 @@
// Classe J e u //--------------------------------------------------------------------------------- // Classe J e u //---------------------------------------------------------------------------------
class Jeu extends Scene { class Jeu extends Scene {
//----------------------------------------------------------------------------------------Attributs //----------------------------------------------------------------------------------------Attributs
/* Declarer ici les attributs de la scene. */ /* Declarer ici les attributs de la scene. */
public carte_ : Array<Array<number>>; public carte_ : Array<Array<number>>;
public wall_ : Sprite; public wall_ : Sprite;
public pas_ : number; public pas_ : number;
public rat_ : Rat; public rat_ : Rat;
public fromage_ : Sprite; public fromage_ : Sprite;
public fraise_ : Sprite; public fraise_ : Sprite;
public arriverx_ : number; public arriverx_ : number;
public arrivery_ : number; public arrivery_ : number;
public compteurfromage_ : number; public compteurfromage_ : number;
public compteurfraise_ : number; public compteurfraise_ : number;
public totalfraise_ : number; public totalfraise_ : number;
public totalfromage_ : 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 compteurfromagemoins_ : number;
public compteurfraisemoins_ : number; public compteurfraisemoins_ : number;
public niveau_ : any;
private idniveau_ : number;
//-------------------------------------------------------------------------------------Constructeur
public constructor(element : HTMLElement) {
super(element,false); //-------------------------------------------------------------------------------------Constructeur
/* Ecrire ici le code qui initialise la scene. */ public constructor(element : HTMLElement) {
this.pas_ = 32; super(element,false);
this.mangerfromage_ = []; /* Ecrire ici le code qui initialise la scene. */
this.mangerfraise_ = []; this.pas_ = 32;
this.compteurfromagemoins_ = 0; this.mangerfromage_ = [];
this.compteurfraisemoins_ = 0; this.mangerfraise_ = [];
this.compteurfromagemoins_ = 0;
this.compteurfraisemoins_ = 0;
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(){
private initialiserCarte(){ // this.carte_ = [];
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_[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_[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_[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_[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 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compteurfraise_ = 0;
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
this.mangerfromage_[i] = []; this.mangerfromage_[i] = [];
this.mangerfraise_[i] = []; this.mangerfraise_[i] = [];
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] == 9){ if (this.carte_[i][j] == 9){
this.arriverx_ = j; this.arriverx_ = j;
this.arrivery_ = i; this.arrivery_ = i;
} }
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"));
this.wall_.setImage("mur.jpg",32,32); this.wall_.setImage("mur.jpg",32,32);
this.wall_.setXY(this.pas_*j,this.pas_*i); this.wall_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.wall_); this.appendChild(this.wall_);
} }
if (this.carte_[i][j] == 8){ if (this.carte_[i][j] == 8){
this.rat_ = new Rat(this,document.createElement("img"),i,j); this.rat_ = new Rat(this,document.createElement("img"),i,j);
this.rat_.setImage("rat.png",32,32); this.rat_.setImage("rat.png",32,32);
this.rat_.setXY(this.pas_*j,this.pas_*i); this.rat_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.rat_); this.appendChild(this.rat_);
} }
if (this.carte_[i][j] == 2){ if (this.carte_[i][j] == 2){
this.fromage_ = new Sprite(document.createElement("img")); this.fromage_ = new Sprite(document.createElement("img"));
this.fromage_.setImage("fromage.png",32,32); this.fromage_.setImage("fromage.png",32,32);
this.fromage_.setXY(this.pas_*j,this.pas_*i); this.fromage_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.fromage_); this.appendChild(this.fromage_);
this.compteurfromage_++; this.compteurfromage_++;
} }
if (this.carte_[i][j] == 3){ if (this.carte_[i][j] == 3){
this.fraise_ = new Sprite(document.createElement("img")); this.fraise_ = new Sprite(document.createElement("img"));
this.fraise_.setImage("fraise.png",32,32); this.fraise_.setImage("fraise.png",32,32);
this.fraise_.setXY(this.pas_*j,this.pas_*i); this.fraise_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.fraise_); this.appendChild(this.fraise_);
} }
if(this.carte_[i][j] == 2){ if(this.carte_[i][j] == 2){
this.mangerfromage_[i][j] = this.fromage_; this.mangerfromage_[i][j] = this.fromage_;
} 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_;
} else { } else {
this.mangerfraise_[i][j] = null; this.mangerfraise_[i][j] = null;
} }
} }
}
console.log(this.mangerfromage_);
console.log(this.mangerfraise_);
console.log(this.carte_);
}
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++){
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_);
}
}
}
this.removeAllChildNodes();
}
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++){
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 start_suite() {
/* Ecrire ici le code qui demarre la scene. */
console.log(this.carte_);
this.initialiserCarte();
this.dessinerLabyrinthe();
this.compteur();
this.rat_.animer();
this.rat_.estArriver();
} }
console.log(this.mangerfromage_); public override start() {
console.log(this.mangerfraise_); /* Ecrire ici le code qui demarre la scene. */
console.log(this.carte_); this.telechargerNiveau(this.idniveau_);
} this.idniveau_++;
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++){
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_);
}
}
} }
this.removeAllChildNodes();
} //--------------------------------------------------------------------------------------------pause
public retirerFraise(y : number, x : number){ public override pause() {
this.carte_[y][x] = 4; /* Ecrire ici le code qui met la scene en pause. */
this.mangerfraise_[y][x] = null; this.rat_.figer();
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;
this.compteurfraisemoins_++;
this.compteurfraise_ = this.totalfraise_ - this.compteurfraisemoins_;
console.log(this.compteurfraise_);
}
}
} }
this.removeAllChildNodes();
} //------------------------------------------------------------------------------------------unpause
public override unpause() {
public replacerPersonnage(ny : number, nx : number, ay : number, ax : number){ /* Ecrire ici le code qui sort la scene de la pause. */
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);
} }
}
//--------------------------------------------------------------------------------------------clean
public compteur(){ public override clean() {
this.totalfromage_ = 0; /* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */
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();
}
//--------------------------------------------------------------------------------------------pause
public override pause() {
/* Ecrire ici le code qui met la scene en pause. */
this.rat_.figer();
} }
//------------------------------------------------------------------------------------------unpause // Fin //-------------------------------------------------------------------------------------------
public override unpause() {
/* Ecrire ici le code qui sort la scene de la pause. */
}
//--------------------------------------------------------------------------------------------clean
public override clean() {
/* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */
}
}
// Fin //-------------------------------------------------------------------------------------------
Loading…
Cancel
Save