From 85a5408baa3b1ee77b72bc8342114bdd56750230 Mon Sep 17 00:00:00 2001 From: Victor Brun Date: Tue, 23 May 2023 21:57:20 +0100 Subject: [PATCH] version avec back end --- build/fin.png | Bin 0 -> 6493 bytes source/Jeu.ts | 128 ++++++++++++++++++++++---------------------------- source/Rat.ts | 31 +++++++----- 3 files changed, 76 insertions(+), 83 deletions(-) create mode 100644 build/fin.png diff --git a/build/fin.png b/build/fin.png new file mode 100644 index 0000000000000000000000000000000000000000..2deff9c1496ef95d4f37822e4ccad80f37d4903f GIT binary patch literal 6493 zcmeAS@N?(olHy`uVBq!ia0y~yVA;UHz`T@$87SiA{4N?uv7|ftIx;Y9?C1WI$O_~u zBzpw;GB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpoCL^Pl&6Lj>_(x z+yDRnzkBDlvZCDb;=H4W4|cUTOcW0JSK3sV|*O$w01UgGKN%KnU5m|tGy^MTqo3=9$y zo-U3d6}R4A^XxkmAj0BkEM@Sy;Q#7xTxK~FJuZIi``|74%|Im2jQ@_(N0HX)GxWLj zH+tE$+C|m!urZ2lXkgW8X5fza#QIC#Id1a zDL(hT9iZ!$3g@ad8676^L+ydI{P4SRw&ySX!XR9?+{;A^{X`Xt75^B!FEEGyx;r zh>HZQVL1mq_JHArB@#g4h8BAyL;}vlOI##i4a;*Fss7{IXz{!|EP1mlx(<2glmRoD zkpIH|F!_Bi)<^$Zw0z$SNVpI;$>I_Tj z#!@$8DdQn+3gYTUU^#)M^uSErqYV^zlL|{Dpf*tKDxV*UUDvo5;6Lf5Mws>*dP zzu>-_KmN;g-P()6@n2@z$JOrno`|D;h@~dL5|>!3SmNRmYqbKj0$ZDLAWABjFR8ueReJxBf>DNMCKVb_1pnI_2Wg+6~_4qEn-K0J`6HmBA0cB|qTnT&}U_ zNQKUxBbpyYer0@p*!^$UQvIq|-FBakukQbD2kJ``H?DxK3?tZ@#ZyO6R)(Qg<)d{3 zF@r#)jOEa&y^5ud7$W04$U_rfi)+_#o98iY_qB0-sA{(Rkhc%GDcOHe{BI?9{Ff`@ zwNLxQ{BOH86O(`njxgN@xNAsCWGW literal 0 HcmV?d00001 diff --git a/source/Jeu.ts b/source/Jeu.ts index ba02690..1b5d07e 100644 --- a/source/Jeu.ts +++ b/source/Jeu.ts @@ -14,16 +14,13 @@ class Jeu extends Scene { public fraise_ : Sprite; public arriverx_ : number; public arrivery_ : number; + public arriver_ : Sprite; public compteurfromage_ : number; public compteurfraise_ : number; - public totalfraise_ : number; - public totalfromage_ : number; public mangerfromage_ : Array>; public mangerfraise_ : Array>; - public compteurfromagemoins_ : number; - public compteurfraisemoins_ : number; public niveau_ : any; - private idniveau_ : number; + public idniveau_ : number; @@ -34,8 +31,8 @@ class Jeu extends Scene { this.pas_ = 32; this.mangerfromage_ = []; this.mangerfraise_ = []; - this.compteurfromagemoins_ = 0; - this.compteurfraisemoins_ = 0; + this.compteurfraise_ = 0; + this.compteurfromage_ = 0; this.idniveau_ = 1; } @@ -45,8 +42,8 @@ class Jeu extends Scene { 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) { + if (requete.readyState == XMLHttpRequest.DONE && requete.status == 200) { + this.niveau_ = JSON.parse(requete.responseText); /* Suite du code */ console.log(this.niveau_.id); @@ -58,66 +55,78 @@ class Jeu extends Scene { } 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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,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; + // dessine la map et place les objets et le rat for(let i = 0 ; i {this.deplacer(event)}; - this.getElement().style.zIndex = "2"; + this.getElement().style.zIndex = "2"; // sert pour que le rat soit toujours au dessus } + //sert a bouger vert le haut jusqu'au mur le plus proche avec un rafraichissement de 20ms 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)'; this.manger(); console.log("oui"); - await new Promise(resolve => setTimeout(resolve, 20)); + await new Promise(resolve => setTimeout(resolve, 20)); //attend 20ms entre chaque mouvement } } + //sert a bouger vert le bas jusqu'au mur le plus proche avec un rafraichissement de 20ms 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)'; this.manger(); - await new Promise(resolve => setTimeout(resolve, 20)); + await new Promise(resolve => setTimeout(resolve, 20)); //attend 20ms entre chaque mouvement } } + //sert a bouger vert la gauche jusqu'au mur le plus proche avec un rafraichissement de 20ms 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)'; this.manger(); - await new Promise(resolve => setTimeout(resolve, 20)); + await new Promise(resolve => setTimeout(resolve, 20)); //attend 20ms entre chaque mouvement } } + //sert a bouger vert la droite jusqu'au mur le plus proche avec un rafraichissement de 20ms 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)'; this.manger(); - await new Promise(resolve => setTimeout(resolve, 20)); + await new Promise(resolve => setTimeout(resolve, 20)); //attend 20ms entre chaque mouvement } } + // sert a deplacer le personnage et si il est arriver demande le prochain niveau private deplacer(event : KeyboardEvent){ if(this.estArriver() == false){ if(event.key == "ArrowLeft"){ @@ -76,19 +77,22 @@ class Rat extends Sprite { if(event.key == "ArrowUp"){ this.haut(); } + }else{ + this.scene_.idniveau_++; + this.scene_.start(); } - } public manger(){ + //sert a bouger le personnage si la case est vide 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){ + }else if(this.scene_.carte_[this.py_][this.px_] == 2){//sert a bouger le personnage si la case est un fromage this.scene_.retirerFromage(this.py_,this.px_); console.log("j'ai mange"); this.scene_.carte_[this.py_][this.px_] = 8; - }else if(this.scene_.carte_[this.py_][this.px_] == 3){ + }else if(this.scene_.carte_[this.py_][this.px_] == 3){//sert a bouger le personnage si la case est une fraise this.scene_.retirerFraise(this.py_,this.px_); console.log("j'ai mange"); this.scene_.carte_[this.py_][this.px_] = 8; @@ -97,14 +101,17 @@ class Rat extends Sprite { } public animer(){ + // ajoute un ecouteur de si il y a une touche presser window.addEventListener("keydown", this.ecouteurDeplacer); } public figer(){ + // enleve l'ecouteur de la touche presser window.removeEventListener("keydown", this.ecouteurDeplacer); } public estArriver(){ + //savoir si le personnage est arriver si oui return un true return this.scene_.carte_[this.scene_.arrivery_][this.scene_.arriverx_] == 8; } } \ No newline at end of file