jeu version 1 fonctionnel WIP compteur

master
Victor BRUN 1 year ago
parent 03e8f82803
commit d4acaba58b

@ -10,8 +10,14 @@ class Jeu extends Scene {
public wall_ : Sprite;
public pas_ : number;
public rat_ : Rat;
public noisette_ : Sprite;
public pastilles_ : Array<Array<Sprite>>;
public fromage_ : Sprite;
public fraise_ : Sprite;
public arriverx_ : number;
public arrivery_ : number;
public compteurfromage_ : number;
public compteurfraise_ : number;
public mangerfromage_ : Array<Array<Sprite>>;
public mangerfraise_ : Array<Array<Sprite>>;
@ -20,47 +26,42 @@ class Jeu extends Scene {
super(element,false);
/* Ecrire ici le code qui initialise la scene. */
this.pas_ = 32;
this.pastilles_ = [];
this.mangerfromage_ = [];
this.mangerfraise_ = [];
}
private initialiserCarte(){
// this.carte_ = [];
// this.carte_[0] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
// this.carte_[1] = [1 ,3 ,2 ,2 ,2 ,1 ,3 ,2 ,2 ,1];
// this.carte_[2] = [1 ,1 ,2 ,1 ,1 ,1 ,2 ,1 ,2 ,1];
// this.carte_[3] = [1 ,2 ,2 ,2 ,1 ,1 ,2 ,1 ,1 ,1];
// this.carte_[4] = [1 ,2 ,1 ,1 ,2 ,2 ,2 ,1 ,2 ,9];
// this.carte_[5] = [1 ,2 ,2 ,2 ,2 ,1 ,2 ,1 ,2 ,1];
// this.carte_[6] = [1 ,2 ,1 ,8 ,1 ,1 ,2 ,2 ,2 ,1];
// this.carte_[7] = [1 ,2 ,1 ,2 ,1 ,1 ,2 ,1 ,1 ,1];
// this.carte_[8] = [1 ,2 ,2 ,2 ,1 ,2 ,2 ,2 ,2 ,1];
// this.carte_[9] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
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 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1 ,0 ,0 ,0 ,0 ,0 ];
}
private dessinerLabyrinthe(){
public dessinerLabyrinthe(){
this.compteurfromage_ = 0;
this.compteurfraise_ = 0;
for(let i = 0 ; i<this.carte_.length; i++){
this.pastilles_[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;
// console.log(this.arriverx_,this.arrivery_);
}
if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img"));
this.wall_.setImage("mur.jpg",32,32);
@ -74,28 +75,68 @@ private dessinerLabyrinthe(){
this.appendChild(this.rat_);
}
if (this.carte_[i][j] == 2){
this.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("fromage.png",32,32);
this.noisette_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.noisette_);
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.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("fraise.png",32,32);
this.noisette_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.noisette_);
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.pastilles_[i][j] = this.noisette_;
this.mangerfromage_[i][j] = this.fromage_;
this.compteurfromage_++;
} else {
this.mangerfromage_[i][j] = null;
}
if(this.carte_[i][j] == 3){
this.mangerfraise_[i][j] = this.fraise_;
this.compteurfraise_++;
} else {
this.pastilles_[i][j] = null;
this.mangerfraise_[i][j] = null;
}
}
}console.log(this.pastilles_);
}
console.log(this.mangerfromage_);
console.log(this.mangerfraise_);
console.log(this.carte_);
console.log(this.compteurfraise_);
console.log(this.compteurfromage_);
}
public retirePastille(){
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.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.removeAllChildNodes();
}
public removeAllChildNodes() {
const scene = document.getElementById('scene')
while (scene.firstChild) {
scene.removeChild(scene.firstChild);
}
}
//--------------------------------------------------------------------------------------------start
public override start() {
@ -121,6 +162,7 @@ public retirePastille(){
//--------------------------------------------------------------------------------------------clean
public override clean() {
/* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */
}
}

@ -20,6 +20,8 @@ class Rat extends Sprite {
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<void>(resolve => setTimeout(resolve, 20));
}
}
@ -28,6 +30,7 @@ class Rat extends Sprite {
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<void>(resolve => setTimeout(resolve, 20));
}
}
@ -36,6 +39,7 @@ class Rat extends Sprite {
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<void>(resolve => setTimeout(resolve, 20));
}
}
@ -44,6 +48,7 @@ class Rat extends Sprite {
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<void>(resolve => setTimeout(resolve, 20));
}
}
@ -65,6 +70,20 @@ class Rat extends Sprite {
}
public manger(){
if(this.scene_.carte_[this.py_][this.px_] == 2 || this.scene_.carte_[this.py_][this.px_] == 4
|| this.scene_.carte_[this.py_][this.px_] == 9 ){
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){
this.scene_.retirerFraise(this.py_,this.px_);
console.log("j'ai mange");
this.scene_.carte_[this.py_][this.px_] = 8;
}
this.scene_.dessinerLabyrinthe();
}
public animer(){
window.addEventListener("keydown", this.ecouteurDeplacer);
}
@ -74,6 +93,6 @@ class Rat extends Sprite {
}
public estArriver(){
return this.scene_.carte_[this.py_][this.px_] == 9;
return this.scene_.carte_[this.scene_.arrivery_][this.scene_.arriverx_] == 8;
}
}
Loading…
Cancel
Save