diff --git a/Makefile b/Makefile index 606513e..f0ee043 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ LIB_DIR = lib JAR = $(LIB_DIR)/* # main -all: $(MAIN_FILE) run clean +all: clean $(MAIN_FILE) run clean $(MAIN_FILE) : $(BIN_DIR)/$(MAIN_FILE).class diff --git a/res/ASCII-Table.svg b/res/ASCII-Table.svg new file mode 100644 index 0000000..6fb11bd --- /dev/null +++ b/res/ASCII-Table.svg @@ -0,0 +1,171 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Environnements/Map.java b/src/Environnements/Map.java index f084c92..1d51691 100644 --- a/src/Environnements/Map.java +++ b/src/Environnements/Map.java @@ -1,13 +1,14 @@ -package Environnements; +package environnements; import java.lang.Object; import java.util.Random; -import Item.Effects; -import Item.Items; +import item.Effects; +import item.Items; public class Map { private Object[][] grid; + private Object[][] emptyGrid; private Random random; public int longueur; @@ -20,15 +21,14 @@ public class Map { this.random = new Random(); this.grid = new Object[this.largeur][this.longueur]; + this.emptyGrid = new Object[this.largeur][this.longueur]; + this.fillGrid(); } public Items getCoordinate(int x, int y) { if (x >= 0 && x < grid[0].length && y >= 0 && y < grid.length) { - Object coordinate = grid[y][x]; - if (coordinate instanceof Items) { - return ((Items)coordinate); - } + return (Items)grid[y][x]; } return null; } @@ -38,9 +38,13 @@ public class Map { } public boolean isGameOver(int[] coordinate) { - if (getCoordinate(longueur, largeur) != null && - getCoordinate(longueur, largeur).getEffects() == Effects.IMPASSABLE) return true; - return false; + Items item = getCoordinate(coordinate[0], coordinate[1]); + + if (item != null) { + Effects effect = item.getEffects(); + return effect == Effects.IMPASSABLE; + } + return true; } public String getStringGrid() { @@ -70,6 +74,10 @@ public class Map { return grid; } + public void cleanGrid() { + this.grid = this.emptyGrid; + } + public void ajoutBordure() { for(int i = 0; i < this.grid.length; i++) { for(int k = 0; k < this.grid[0].length; k++) { @@ -88,6 +96,16 @@ public class Map { } } + public void addCoordinate(int[] coordinate, Items items) { + for(int i = 0; i < this.grid.length; i++) { + for(int k = 0; k < this.grid[0].length; k++) { + if(i == coordinate[1] && k == coordinate[0]) { + this.grid[i][k] = items; + } + } + } + } + private void randomize(Items item, int number) { for(int i = 0; iCeci est l'enumération où il y aura tout les effets disponible dans le projet. @@ -26,5 +26,7 @@ public enum Effects { /** *

impossible à passer à travers. */ - IMPASSABLE, Effects; + IMPASSABLE, + + VOID; } diff --git a/src/Item/Items.java b/src/Item/Items.java index c63da9b..6a575ee 100644 --- a/src/Item/Items.java +++ b/src/Item/Items.java @@ -1,4 +1,4 @@ -package Item; +package item; /** * Cette enumération contient tout les items à effets disponnible dans le jeu. @@ -8,7 +8,8 @@ public enum Items { BODY("corps", Effects.IMPASSABLE), HEAD("tete", Effects.IMPASSABLE), - VOID("void", null), + + VOID("void", Effects.VOID), FRAISE("fraise", Effects.INVINCIBILITY), ORANGE("orange", Effects.POWER), diff --git a/src/Main.java b/src/Main.java index 4a839e2..22a868b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,20 +1,15 @@ -import java.lang.Object; -import java.util.function.Supplier; - -import Environnements.Map; -import Item.Items; +import environnements.Map; +import personnages.Personnage; import personnages.Player; public class Main { public static void main(String[] args) { int n = 2; - Map map = new Map(10, 10); + + Personnage[] players = new Personnage[] { + new Player("player1", n, new int[]{2, 2}) + }; - Player player1 = new Player(n, new int[]{1, 1}); - Player player2 = new Player(n, new int[]{9, 9}); - - while(!map.isGameOver(player1.getCoordinate()) || !map.isGameOver(player2.getCoordinate())) { - player1.changeCoordinate(); - } + display.Terminal.run(players, new Map(10, 10), 2); } } diff --git a/src/display/Terminal.java b/src/display/Terminal.java new file mode 100644 index 0000000..91115bc --- /dev/null +++ b/src/display/Terminal.java @@ -0,0 +1,63 @@ +package display; + +import java.util.Scanner; + +import environnements.Map; +import item.Items; +import personnages.Personnage; +import personnages.Player; + +public class Terminal { + private static void clearTerminal() { + System.out.println("\u001b[2J \u001b[H"); + } + + private static void showMap(Object[][] grid) { + for (int i = 0; i la liste de toute les coordonnées en fonction de N. Si N = 2, * tout les deux tours, la taille du serpent augmente de 1. Si N = 3, @@ -32,19 +34,28 @@ public class Personnage { *

le constructor definie un arrayList pour {@link #coordinate} * et defini n. * + * @param name est le nom du personnage. * @param n est une variable qui contient le nombre de tour avant * l'augmentation de taille. * @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 n, int[] coordinate) { this.coordinate = new ArrayList(); this.coordinate.add(coordinate); this.n = n; } + public String getName() { + return nom; + } + public int incrementRound() { return ++this.round; } + + public int[] getCoordinate() { + return coordinate.get(0); + } } diff --git a/src/personnages/Player.java b/src/personnages/Player.java index 4201cf2..09fa174 100644 --- a/src/personnages/Player.java +++ b/src/personnages/Player.java @@ -1,5 +1,7 @@ package personnages; +import static java.util.Arrays.toString; + import java.util.Scanner; /** @@ -16,32 +18,24 @@ public class Player extends Personnage { * est représenté comme {x, y} et qui represente les * coordonnées de la tête du personnage. */ - public Player(int n, int[] coordinate) { - super(n, coordinate); + public Player(String name, int n, int[] coordinate) { + super(name, n, coordinate); } - public void changeCoordinate() { - Scanner scanner = new Scanner(System.in); - String value; - - do { - value = scanner.nextLine(); - } while (!moveCoordinate((int)'w')); - - scanner.close(); + public boolean changeCoordinate(String input) { + if (input.length() > 0) { + return moveCoordinate(input.charAt(0)); + } + return false; } - - public int[] getCoordinate() { - return coordinate.get(0); - } - + private boolean moveCoordinate(int keys) { switch (keys) { - case 119: Mouvement.HAUT.editCoordinate(getCoordinate()); break; - case 115: Mouvement.BAS.editCoordinate(getCoordinate()); break; - case 97: Mouvement.GAUCHE.editCoordinate(getCoordinate()); break; - case 100: Mouvement.DROITE.editCoordinate(getCoordinate()); break; - default: return false; + case 0x77: Mouvement.HAUT.editCoordinate(getCoordinate()); break; // w + case 0x73: Mouvement.BAS.editCoordinate(getCoordinate()); break; // s + case 0x61: Mouvement.GAUCHE.editCoordinate(getCoordinate()); break; // a + case 0x64: Mouvement.DROITE.editCoordinate(getCoordinate()); break; // d + default: return false; } return true; } diff --git a/src/personnages/Robot.java b/src/personnages/Robot.java index 038e100..33601a5 100644 --- a/src/personnages/Robot.java +++ b/src/personnages/Robot.java @@ -1,7 +1,7 @@ package personnages; public class Robot extends Personnage { - public Robot(int size, int[] coordinate) { - super(size, coordinate); + public Robot(String name, int size, int[] coordinate) { + super(name, size, coordinate); } } \ No newline at end of file