Skip to content

Commit

Permalink
correction code
Browse files Browse the repository at this point in the history
  • Loading branch information
Svvmy committed Jan 11, 2024
1 parent b8cf437 commit 4587d40
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/main/java/Classes/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void updateGrid(int direction) {
// Mettre à jour la position des fantômes
deplacerFantomes();

// Afficher la grille mise à jour (peut être envoyée au front-end)
// Afficher la grille mise à jour
afficherGrille(this.terrain.getGrille());
}
}
Expand Down Expand Up @@ -192,10 +192,8 @@ private boolean toutesLesBoulesMangees() {
}
public void deplacerFantomes() {
for (Fantome fantome : this.fantomes) {
System.out.println("MOUVVVVVV");
fantome.deplacer(this.terrain.getGrille()); // Appeler la méthode deplacement du fantome
}
System.out.println("FINISH depalcerFantomes");
}

public void afficherGrille(char[][] grille) {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/Classes/PacMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void deplacer(char[][] terrain, int direction) {
perdreVies();
}
// System.out.println("peutSeDeplacer: "+peutSeDeplacer(terrain, direction, positionX, positionY));
if (peutSeDeplacer(this.game.getTerrain(), direction, positionX, positionY)){
if (peutSeDeplacer(terrain, direction, positionX, positionY)){
// Déplacer le Pacman dans la direction choisie
switch (direction) {
case 0:
Expand All @@ -118,8 +118,8 @@ public void deplacer(char[][] terrain, int direction) {
}
System.out.println("MAJ POSITION");
// Mettre à jour la grille avec la nouvelle position du pacman
terrain[anciennePositionX][anciennePositionY] = '.'; // Ancienne position vide
terrain[position.getPositionX()][position.getPositionY()] = 'P'; // Nouvelle position avec le Pacman
this.game.getTerrain()[anciennePositionX][anciennePositionY] = '.'; // Ancienne position vide
this.game.getTerrain()[position.getPositionX()][position.getPositionY()] = 'P'; // Nouvelle position avec le Pacman

System.out.println("Postion Pacman après maj "+ position.getPositionX() +" "+ position.getPositionY());
}
Expand All @@ -146,37 +146,38 @@ private boolean peutSeDeplacer(char[][] terrain, int direction, int positionX, i
newY--; // Déplacement vers la gauche
break;
default:
System.out.println("Direction non Valide "+direction);
return false; // Direction non valide
}

// Vérifier les limites de la grille
if (newX < 0 || newX >= this.game.getTerrain()[0].length || newY < 0 || newY >= this.game.getTerrain().length) {
if (newX < 0 || newX >= terrain[0].length || newY < 0 || newY >= terrain.length) {
System.out.println("Pacman Limite de grille " + direction);
return false; // En dehors de la grille
}

// Vérifier s'il y a un mur à la nouvelle position
if (this.game.getTerrain()[newX][newY] == 'M') {
if (terrain[newX][newY] == 'M') {
System.out.println("Collision avec un Mur");
return false; // Mur présent
}
if (this.game.getTerrain()[newX][newY] == 'F') {
if (terrain[newX][newY] == 'F') {
// Collision avec un fantôme, perdre une vie
System.out.println("Collision avec un Fantome");
this.game.getPacMan().perdreVies();
return false;
}

// Vérifier s'il y a une boule ou une super boule à la nouvelle position
if (this.game.getTerrain()[newX][newY] == 'o') {
if (terrain[newX][newY] == 'o') {
this.game.getPacMan().mangerBoule();
this.game.getTerrain()[newX][newY] = '.';
System.out.println("Boule!! : + 25 points");

return true;
}

if (this.game.getTerrain()[newX][newY] == 'O') {
if (terrain[newX][newY] == 'O') {
// Manger la super boule, augmenter le score de 50 points
this.game.getPacMan().mangerSuperBoule();
this.game.getTerrain()[newX][newY] = '.';
Expand All @@ -185,7 +186,7 @@ private boolean peutSeDeplacer(char[][] terrain, int direction, int positionX, i

return true;
}
if (this.game.getTerrain()[newX][newY] == 'C' || this.game.getTerrain()[newX][newY] == 'B' || this.game.getTerrain()[newX][newY] == 'K') {
if (terrain[newX][newY] == 'C' || terrain[newX][newY] == 'B' || terrain[newX][newY] == 'K') {
Fruit fruit = trouverFruit(newX, newY);
if (fruit != null) {
this.game.getPacMan().mangerFruit(fruit);
Expand Down
52 changes: 34 additions & 18 deletions src/main/java/Classes/Terrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,41 @@ public Terrain() {
{'F', '.', '.', '.', '.', 'M', 'M', 'M', '.', '.', '.', 'o', 'K', 'M', '.'},
};



grilleNiveau2 = new char[][] {
{'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
{'M', 'P', 'o', 'M', '.', 'o', 'M', 'K', 'M', 'C', '.', 'M', 'o', 'B', 'M'},
{'M', 'o', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', 'o', 'M'},
{'M', '.', '.', 'o', '.', 'M', 'B', '.', 'C', 'M', '.', 'o', '.', '.', 'M'},
{'M', 'M', 'M', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', 'M', 'M', 'M', 'M'},
{'M', 'o', '.', '.', '.', 'o', 'M', 'O', 'M', 'o', '.', '.', '.', 'o', 'M'},
{'M', '.', 'M', 'M', 'M', '.', 'M', '.', 'M', '.', 'M', 'M', 'M', '.', 'M'},
{'M', 'K', 'M', '.', 'M', 'o', 'M', 'B', 'M', 'o', 'M', '.', 'M', 'K', 'M'},
{'M', '.', 'M', 'M', 'M', '.', 'M', '.', 'M', '.', 'M', 'M', 'M', '.', 'M'},
{'M', 'o', '.', '.', '.', 'o', 'M', 'C', 'M', 'o', '.', '.', '.', 'o', 'M'},
{'M', 'M', 'M', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', 'M', 'M', 'M', 'M'},
{'M', '.', '.', 'o', '.', 'M', 'K', '.', 'O', 'M', '.', 'o', '.', '.', 'M'},
{'M', 'o', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', 'o', 'M'},
{'M', 'B', 'o', 'M', '.', 'o', 'M', '.', 'M', 'C', '.', 'M', 'o', 'F', 'M'},
{'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
grilleNiveau2 = new char[][] {
{'P', 'o', 'O', 'F', 'M', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
{'.', 'M', '.', 'M', 'M', '.', '.', '.', 'M', 'M', '.', 'o', 'M', '.', '.'},
{'.', 'M', 'M', 'O', 'M', 'M', '.', 'M', '.', '.', '.', '.', '.', '.', '.'},
{'O', '.', 'M', '.', '.', 'M', '.', 'M', '.', '.', 'O', 'M', 'M', 'M', '.'},
{'.', '.', '.', '.', '.', '.', '.', 'M', 'M', 'M', '.', '.', '.', 'M', 'M'},
{'.', '.', 'M', '.', '.', 'M', '.', 'O', 'M', '.', '.', 'M', '.', '.', '.'},
{'.', '.', '.', 'O', '.', '.', '.', 'M', '.', 'M', '.', 'M', 'M', 'M', '.'},
{'M', 'M', 'M', '.', 'M', '.', 'M', '.', 'M', '.', 'M', '.', 'M', '.', 'o'},
{'.', '.', 'M', '.', 'M', '.', 'M', '.', 'M', 'o', 'M', '.', '.', '.', '.'},
{'M', 'M', 'M', '.', '.', '.', 'M', 'M', 'M', '.', '.', '.', 'M', 'M', '.'},
{'.', 'o', '.', '.', '.', '.', '.', '.', 'M', '.', 'O', '.', 'M', '.', '.'},
{'M', 'M', 'M', 'M', 'M', 'M', 'M', '.', '.', '.', '.', 'O', 'M', '.', '.'},
{'.', '.', '.', 'M', '.', '.', '.', '.', '.', 'M', '.', 'M', 'M', 'O', '.'},
{'.', 'O', '.', 'M', '.', '.', '.', '.', '.', '.', '.', 'M', '.', '.', '.'},
{'F', '.', '.', '.', '.', 'M', 'M', 'M', '.', '.', '.', 'o', '.', 'M', '.'}
};

// grilleNiveau2 = new char[][] {
// {'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
// {'M', 'P', 'o', 'M', '.', 'o', 'M', 'K', 'M', 'C', '.', 'M', 'o', 'B', 'M'},
// {'M', 'o', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', 'o', 'M'},
// {'M', '.', '.', 'o', '.', 'M', 'B', '.', 'C', 'M', '.', 'o', '.', '.', 'M'},
// {'M', 'M', 'M', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', 'M', 'M', 'M', 'M'},
// {'M', 'o', '.', '.', '.', 'o', 'M', 'O', 'M', 'o', '.', '.', '.', 'o', 'M'},
// {'M', '.', 'M', 'M', 'M', '.', 'M', '.', 'M', '.', 'M', 'M', 'M', '.', 'M'},
// {'M', 'K', 'M', '.', 'M', 'o', 'M', 'B', 'M', 'o', 'M', '.', 'M', 'K', 'M'},
// {'M', '.', 'M', 'M', 'M', '.', 'M', '.', 'M', '.', 'M', 'M', 'M', '.', 'M'},
// {'M', 'o', '.', '.', '.', 'o', 'M', 'C', 'M', 'o', '.', '.', '.', 'o', 'M'},
// {'M', 'M', 'M', '.', 'M', 'M', 'M', 'M', 'M', 'M', '.', 'M', 'M', 'M', 'M'},
// {'M', '.', '.', 'o', '.', 'M', 'K', '.', 'O', 'M', '.', 'o', '.', '.', 'M'},
// {'M', 'o', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', '.', 'M', 'M', 'o', 'M'},
// {'M', 'B', 'o', 'M', '.', 'o', 'M', '.', 'M', 'C', '.', 'M', 'o', 'F', 'M'},
// {'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
// };
grilleNiveau3 = new char[][] {
{'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M'},
{'M', 'P', 'o', 'M', '.', 'K', 'M', '.', 'M', 'o', 'C', 'M', '.', 'B', 'M'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public ResponseEntity<Game> loadMap() {
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) {
Game currentGame = this.game;

DirectionWrapper directionConverter = new DirectionWrapper(directionData);

System.out.println("direction data "+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());
Expand Down

0 comments on commit 4587d40

Please sign in to comment.