Skip to content

Commit

Permalink
Séparation UpdateGrid fantome et pacman
Browse files Browse the repository at this point in the history
  • Loading branch information
Svvmy committed Jan 16, 2024
1 parent 4ee1bcc commit 97b7540
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 25 deletions.
71 changes: 51 additions & 20 deletions src/main/java/Classes/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,64 @@ public Game() {
this.fantomes = new ArrayList<>();
}

public void updateGrid(int direction) {
System.out.println("UPDATEGRID "+ direction);

if(this.started && !this.collisionEnCours){ // si le jeu est toujours en cours
/*Mettre à jour la position du Pac-Man en fonction de la direction
on recoit -1 pour la direction si il ne bouge pas sinon 0,1,2 ou 3*/
// public void updateGrid(int direction) {
// System.out.println("UPDATEGRID "+ direction);
//
// if(this.started && !this.collisionEnCours){ // si le jeu est toujours en cours
// /*Mettre à jour la position du Pac-Man en fonction de la direction
// on recoit -1 pour la direction si il ne bouge pas sinon 0,1,2 ou 3*/
//
// if (direction != -1) {
// pacMan.deplacer(this.terrain.getGrille(), direction);
//// this.lastDirections.add(direction);
// }
//
// // Mettre à jour la position des fantômes
// if(!this.collisionEnCours){
// System.out.println("deplacer FANTOMEEEE");
// deplacerFantomes();
// }
//
// // Afficher la grille mise à jour
// afficherGrille(this.terrain.getGrille());
// }else
// System.out.println("Collision en cours");
// if (!this.started){
// System.out.println("FIN DU JEU Valeur de Started "+this.started);
// }
// }


public void updateGridPacman(int direction) {
System.out.println("UPDATEGRIDFANTOME " + direction);

if (this.started && !this.collisionEnCours) {
/* Mettre à jour la position du Pac-Man en fonction de la direction
On reçoit -1 pour la direction si il ne bouge pas sinon 0,1,2 ou 3 */
if (direction != -1) {
pacMan.deplacer(this.terrain.getGrille(), direction);
// Afficher la grille mise à jour avec le déplacement du Pac-Man
afficherGrille(this.terrain.getGrille());
}

if (direction != -1) {
pacMan.deplacer(this.terrain.getGrille(), direction);
// this.lastDirections.add(direction);
// Afficher la grille mise à jour
afficherGrille(this.terrain.getGrille());
} else {
System.out.println("Collision en cours ou fin du jeu");
}
}

// Mettre à jour la position des fantômes
if(!this.collisionEnCours){
System.out.println("deplacer FANTOMEEEE");
public void updateFantomes() {
if (this.started && !this.collisionEnCours) {
deplacerFantomes();
}

// Afficher la grille mise à jour
afficherGrille(this.terrain.getGrille());
}else
System.out.println("Collision en cours");
if (!this.started){
System.out.println("FIN DU JEU Valeur de Started "+this.started);
// Afficher la grille mise à jour après le déplacement des fantômes
afficherGrille(this.terrain.getGrille());
} else {
System.out.println("Collision en cours ou fin du jeu");
}
}


private void preparerNouveauNiveau() {
this.checkWin(); // verifie si on a win
if(!this.isWin){ // sinon on continue
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Classes/Terrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public Terrain() {
{'M', 'o', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', 'M'},
{'M', 'o', '.', '.', 'M', 'M', '.', '.', 'M', 'M', '.', '.', 'M', 'M', '.', '.', 'M', 'M', '.', '.', '.', 'M'},
{'M', 'o', '.', '.', '.', '.', '.', '.', 'M', '.', '.', '.', '.', 'M', '.', '.', '.', '.', '.', '.', '.', 'M'},
{'M', 'o', '.', '.', '.', '.', '.', '.', 'M', 'F', '.', '.', 'P', 'M', '.', '.', '.', '.', '.', '.', '.', 'M'},
{'M', 'o', '.', '.', '.', '.', '.', '.', 'M', 'F', '.', '.', '.', 'M', '.', '.', '.', '.', '.', '.', '.', 'M'},
{'M', 'o', 'M', '.', 'M', 'M', '.', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', '.', 'M', 'M', '.', 'M', '.', 'M'},
{'M', 'o', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', 'M'},
{'M', 'o', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', 'M'},
{'M', 'o', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', 'M'},
{'M', 'o', 'M', 'M', '.', 'M', '.', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', '.', 'M', '.', 'M', 'M', '.', 'M'},
{'M', 'o', '.', '.', '.', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', '.', '.', '.', 'M'},
{'M', 'o', '.', '.', '.', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'M', '.', '.', '.', '.', 'M'},
{'M', 'o', '.', '.', '.', 'M', '.', '.', '.', '.', '.', '.', 'P', '.', '.', '.', 'M', '.', '.', '.', '.', 'M'},
{'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
};

Expand Down
29 changes: 26 additions & 3 deletions src/main/java/com/pacman/pacman/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,38 @@ public String hello() {
return "Déploiement du back a été réalisé avec succès !";
}

@PostMapping("/update-grid")
public ResponseEntity<Game> updateGrid(@RequestBody String directionData) {
// @PostMapping("/update-grid")
// public ResponseEntity<Game> updateGridFantome(@RequestBody String directionData) {
// Game currentGame = this.game;
//
// DirectionWrapper directionConverter = new DirectionWrapper(directionData);
//
// System.out.println("FRONT : Direction recu = "+directionData);
// // Mettre à jour la grille avec la nouvelle direction
// currentGame.updateGrid(directionConverter.getDirection());
// System.out.println("direction recu convertit "+directionConverter.getDirection());
// return ResponseEntity.ok(currentGame);
// }

@PostMapping("/update-grid-fantome")
public ResponseEntity<Game> updateGridFantome() {
Game currentGame = this.game;

System.out.println("UPADATE FANTOME");
// Mettre à jour la grille avec la nouvelle direction
currentGame.updateFantomes();
return ResponseEntity.ok(currentGame);
}

@PostMapping("/update-grid-pacman")
public ResponseEntity<Game> updateGridPacman(@RequestBody String directionData) {
Game currentGame = this.game;
System.out.println("UPADATE PACMAN");
DirectionWrapper directionConverter = new DirectionWrapper(directionData);

System.out.println("FRONT : Direction recu = "+directionData);
// Mettre à jour la grille avec la nouvelle direction
currentGame.updateGrid(directionConverter.getDirection());
currentGame.updateGridPacman(directionConverter.getDirection());
System.out.println("direction recu convertit "+directionConverter.getDirection());
return ResponseEntity.ok(currentGame);
}
Expand Down

0 comments on commit 97b7540

Please sign in to comment.