back integrer rajoue de niveau WIP

master
Victor BRUN 1 year ago
parent d744b5ae39
commit c95360ef1a

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