diff --git a/src/Characters/Personnage.java b/src/Characters/Personnage.java
index c02f5f0..68a99bb 100644
--- a/src/Characters/Personnage.java
+++ b/src/Characters/Personnage.java
@@ -10,9 +10,10 @@ import Objects.Snake;
* personnage jouable.
*/
public class Personnage {
- private int n;
+ public static int n;
private int round;
private int size = 0;
+ private String name;
/**
*
la liste de toute les coordonnées en fonction de N. Si N = 2,
@@ -33,11 +34,11 @@ public class Personnage {
* @param coordinate est la variable qui contient les coordonnées
* qui sont placé par la suite dans {@link #coordinate}[0]}
*/
- protected Personnage(int n, int[] coordinate) {
+ protected Personnage(String name, int[] coordinate) {
this.coordinate = new ArrayList();
this.coordinate.add(coordinate);
- this.n = n;
+ this.name = name;
}
/**
@@ -118,13 +119,19 @@ public class Personnage {
* @param mouvements le mouvement utilisé pour deplacer le serpent
*/
public void moveSnake(Mouvements mouvements) {
- mouvements.editCoordinate(this.coordinate.get(0));
+
+ int[] oldHeadPosition = getPrimaryCoordinate().clone();
- for(int i = this.coordinate.size() - 1; i>1; i--) {
- int[] value = this.coordinate.get(i-1);
- this.coordinate.set(i, value);
+ for (int i = this.coordinate.size() - 1; i > 0; i--) {
+ this.coordinate.set(i, this.coordinate.get(i - 1).clone());
}
+ mouvements.editCoordinate(oldHeadPosition);
+ this.coordinate.set(0, oldHeadPosition);
}
+
+ public String getName() {
+ return name;
+ }
public Mouvements getMouvement(Integer keys) {
switch (keys) {
diff --git a/src/Characters/Players.java b/src/Characters/Players.java
index 7e69f35..311566e 100644
--- a/src/Characters/Players.java
+++ b/src/Characters/Players.java
@@ -1,8 +1,8 @@
package Characters;
public class Players extends Personnage {
- public Players(int[] coordinate, int n) {
- super(n, coordinate);
+ public Players(String name, int[] coordinate) {
+ super(name, coordinate);
}
public Integer changeCoordinate(String input) {
diff --git a/src/Characters/Robot.java b/src/Characters/Robot.java
index ddc6640..598e215 100644
--- a/src/Characters/Robot.java
+++ b/src/Characters/Robot.java
@@ -2,8 +2,8 @@ package Characters;
public class Robot extends Personnage {
- protected Robot(int[] coordinate, int n) {
- super(n, coordinate);
+ protected Robot(String name, int[] coordinate) {
+ super(name, coordinate);
}
}
diff --git a/src/Environnement/Map.java b/src/Environnement/Map.java
index 2b9741c..38e2915 100644
--- a/src/Environnement/Map.java
+++ b/src/Environnement/Map.java
@@ -44,6 +44,10 @@ public class Map {
this.largeur = largeur;
this.grid = new Object[this.longueur][this.largeur];
+
+ this.ObjectItems = new ArrayList<>();
+ this.coordinateItems = new ArrayList<>();
+
this.fillGrid();
}
@@ -51,8 +55,9 @@ public class Map {
* cette fonction clear toute la grille qui
* contient le jeu.
*/
- public void clearMap() {
+ public void clearMap(boolean edges) {
this.fillGrid();
+ if(edges) this.addEdges();
}
/**
@@ -96,6 +101,7 @@ public class Map {
randomize(objects[i], value);
}
randomize(objects[lengthObjects], number);
+ placeObjects();
}
/**
@@ -124,12 +130,11 @@ public class Map {
}
}
- private boolean isGamefinishedImpassable(int key, Personnage personnage) {
- int[] coordinate = personnage.getMouvement(key).getCoordinate();
+ private boolean isGamefinishedImpassable(Personnage personnage) {
int[] playerCoordinate = personnage.getPrimaryCoordinate();
- int y = coordinate[1] + playerCoordinate[1];
- int x = coordinate[0] + playerCoordinate[0];
+ int y = playerCoordinate[1];
+ int x = playerCoordinate[0];
Object grid = this.getGrid()[y][x];
@@ -147,7 +152,8 @@ public class Map {
if (isOutX || isOutY) {
return true;
}
- return false;
+ System.out.println(isGamefinishedImpassable(personnage));
+ return isGamefinishedImpassable(personnage);
}
private void fillGrid() {
@@ -158,17 +164,24 @@ public class Map {
}
}
- private void randomize(Object item, int number) {
+ private void randomize(Object object, int number) {
Random random = new Random();
- for(int i = 0; i Cette fonction est uniquement destiné pour la classe
* Players pour recuperer l'input dans le terminal.
@@ -35,60 +51,19 @@ public class Terminal {
return input.intValue();
}
- /**
- * print toute la map.
- * @param map
- */
- private static void printMap(Map map) {
- Object[][] mapObjects = map.getGrid();
-
- for (int i = 0; i personnageCoordinate = personnage.getCoordinate();
+
+ int[] primaryCoordinate = personnage.getPrimaryCoordinate();
+
+ if (personnageCoordinate.size() > 1) {
+ int[] secondCoordinate = personnageCoordinate.get(1);
+
+ // UP DOWN LEFT RIGHT
+ boolean[] isHead = new boolean[] {
+ primaryCoordinate[0] == secondCoordinate[0] && primaryCoordinate[1] > secondCoordinate[1], // UP
+ primaryCoordinate[0] == secondCoordinate[0] && primaryCoordinate[1] < secondCoordinate[1], // DOWN
+ primaryCoordinate[1] == secondCoordinate[1] && primaryCoordinate[0] > secondCoordinate[0], // LEFT
+ primaryCoordinate[1] == secondCoordinate[1] && primaryCoordinate[0] < secondCoordinate[0] // RIGHT
+ };
+
+ if (isHead[0]) {System.out.print(" \u21E9 ");return;}
+ else if (isHead[1]) {System.out.print(" \u21E7 ");return;}
+ else if (isHead[2]) {System.out.print(" \u21E8 ");return;}
+ else if (isHead[3]) {System.out.print(" \u21E6 ");return;}
+ }
+ }
+ System.out.print(" \u21E8 ");return;
+ }
+
+
+
+ private static Personnage searchSnake(Personnage[] personnages, int x, int y) {
+ for (Personnage personnage : personnages) {
+ int[] primaryCoordinate = personnage.getPrimaryCoordinate();
+
+ int primaryY = primaryCoordinate[0];
+ int primaryX = primaryCoordinate[1];
+
+ if (primaryX == x && primaryY == y) {
+ return personnage;
+ }
+ }
+ return null;
+ }
+
+ private static void printWall(Object[][] map, int x, int y) {
+ // UP DOWN LEFT RIGHT
+ boolean[] isWall = new boolean[4];
+
+ if (y > 0) isWall[0] = map[y - 1][x] == Items.WALL; else isWall[0] = false;
+ if (y < map.length - 1) isWall[1] = map[y + 1][x] == Items.WALL; else isWall[1] = false;
+ if (x > 0) isWall[2] = map[y][x - 1] == Items.WALL; else isWall[2] = false;
+ if (x < map[0].length - 1) isWall[3] = map[y][x + 1] == Items.WALL; else isWall[3] = false;
+
+ if (isWall[0] && isWall[1] && isWall[2] && isWall[3]) {System.out.print("\u2550\u256C\u2550");return;}
+ else if (isWall[0] && isWall[1] && isWall[3]) {System.out.print("\u2560");return;}
+ else if (isWall[0] && isWall[1] && isWall[2]) {System.out.print("\u2563");return;}
+ else if (isWall[0] && isWall[2] && isWall[3]) {System.out.print("\u2550\u2569\u2550");return;}
+ else if (isWall[1] && isWall[2] && isWall[3]) {System.out.print("\u2550\u2566\u2550");return;}
+ else if (isWall[0] && isWall[1]) {System.out.print("\u2551");return;}
+ else if (isWall[2] && isWall[3]) {System.out.print("\u2550\u2550\u2550");return;}
+ else if (isWall[0] && isWall[2]) {System.out.print("\u255D ");return;}
+ else if (isWall[0] && isWall[3]) {System.out.print("\u255A");return;}
+ else if (isWall[1] && isWall[2]) {System.out.print("\u2557 ");return;}
+ else if (isWall[1] && isWall[3]) {System.out.print("\u2554");return;}
+ else {System.out.print("\u2550\u256C\u2550");return;}
+ }
+}
diff --git a/src/display/Test.java b/src/display/Test.java
deleted file mode 100644
index 59c7a0a..0000000
--- a/src/display/Test.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package Display;
-
-import java.util.Scanner;
-
-import Characters.Personnage;
-import Characters.Players;
-import Characters.Robot;
-import Environnement.Map;
-import Objects.Fruits;
-import Objects.Items;
-import Objects.Snake;
-
-public class Test {
- private static Scanner scanner = new Scanner(System.in);
- private static String name = new String();
-
- /**
- * cette fonction clear le terminal et le remet en
- * haut a gauche de la ligne.
- */
- private static void clearTerminal() {
- System.out.println("\u001b[2J \u001b[H");
- }
-
- private static int getInput(Scanner scanner, Players player) {
- String value = new String();
- Integer input = null;
-
- do {
- value = scanner.nextLine();
- input = player.changeCoordinate(value);
- } while(player.getMouvement(input) == null);
-
- return input.intValue();
- }
-
- private static void printMap(Map map) {
- Object[][] mapObjects = map.getGrid();
- for (int i = 0; i Cette fonction est uniquement destiné pour la classe
+ * Players pour recuperer l'input dans le terminal.
+ * @param scanner
+ * @param player
+ * @return il retourne int qui est le char en ascii
+ */
+ private static int getInput(Scanner scanner, Players player) {
+ String value = new String();
+ Integer input = null;
+
+ do {
+ value = scanner.nextLine();
+ input = player.changeCoordinate(value);
+ }while(player.getMouvement(input) == null);
+
+ return input.intValue();
+ }
+
+ /**
+ * print toute la map.
+ * @param map
+ */
+ private static void printMap(Map map) {
+ Object[][] mapObjects = map.getGrid();
+
+ for (int i = 0; i