diff --git a/Makefile b/Makefile index f016124..606513e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ LIB_DIR = lib JAR = $(LIB_DIR)/* # main -all: $(MAIN_FILE) run clean +all: $(MAIN_FILE) run clean $(MAIN_FILE) : $(BIN_DIR)/$(MAIN_FILE).class diff --git a/src/Environnements/Fruits.java b/src/Environnements/Fruits.java deleted file mode 100644 index b286e73..0000000 --- a/src/Environnements/Fruits.java +++ /dev/null @@ -1,26 +0,0 @@ -package Environnements; - -import Item.Effects; -import Item.Items; -import java.util.Random; - -public class Fruits{ - String typeFruit; - Effects bonus; - - public Fruits(){ - Random r=new Random(); - Items [] fruits=new Items[] {Items.BANANE,Items.FRAISE,Items.ORANGE}; - int q=r.nextInt(3); - this.typeFruit=fruits[q].getName(); - this.bonus=fruits[q].getEffects(); - } - - public void getFruit(){ - System.out.println(this.typeFruit); - } - - public void getBonus(){ - System.out.println(this.bonus); - } -} \ No newline at end of file diff --git a/src/Environnements/Map.java b/src/Environnements/Map.java index d472eff..53ba3e1 100644 --- a/src/Environnements/Map.java +++ b/src/Environnements/Map.java @@ -3,6 +3,7 @@ package Environnements; import java.lang.Object; import java.util.Random; +import Item.Effects; import Item.Items; public class Map { @@ -27,15 +28,20 @@ public class Map { if (coordinate instanceof Items) { return ((Items) coordinate).getName(); } + return "null"; } - return "Empty"; + return "void"; + } + + public Items getItems(int[] coordinate) { + return (Items)getGrid()[coordinate[1]][coordinate[0]]; } public String getStringGrid() { StringBuffer stringGrid = new StringBuffer(); - for(Object[] i : this.grid) { - for(Object value : i) { + for(Object[] listValue : this.grid) { + for(Object value : listValue) { stringGrid.append(value); } stringGrid.append("\n"); diff --git a/src/Environnements/Murs.java b/src/Environnements/Murs.java deleted file mode 100644 index b424c32..0000000 --- a/src/Environnements/Murs.java +++ /dev/null @@ -1,56 +0,0 @@ -package Environnements; - -import Item.Items; - -public class Murs{ - int debut_horizontal; - int debut_vertical; - int longueur; - int largeur; - - public Murs(int debut_horizontal,int debut_vertical,int longueur,int largeur){ - this.debut_horizontal=debut_horizontal; - this.debut_vertical=debut_vertical; - this.longueur=longueur; - this.largeur=largeur; - } - - /** - *

Accéder à la variable de position horizontale - * @return {@code debut_horizontal} - */ - public int getDebutHorizontal(){ - return this.debut_horizontal; - } - - public int getDebutVertical(){ //Accéder à la variable de position verticale - return this.debut_vertical; - } - - public int getLongueur(){ //Accéder à la variable Longueur - return this.longueur; - } - - public int getLargeur(){ //Accéder à la variable Largeur - return this.largeur; - } - - public boolean murValide(Map m){ //Vérifie que l'emplacement du mur est correct - if (this.debut_horizontal+this.longueur>m.longueur || this.debut_vertical+largeur>m.largeur){ - System.out.println("Emplacement de mur invalide"); - return false; - } - return true; - } - - public void insereMur(Map m){ //Positionner un mur à un endroit prédéfini - boolean b=this.murValide(m); - if (b){ - for (int i=this.debut_horizontal;i taille du serpent. + */ + private int size; + private int n; // N - protected ArrayList CoordinateSnake; - private ArrayList effectsList; + /** + *

une variable pour changer le round pour chaque fois + * que la manche est fini seulement pour le personnage. + */ + private int round; - protected Personnage(int size, int[] coordinate) { - this.coordinate = coordinate; - this.size = size; - } - - public int[] getCoordinate() { - return coordinate; + /** + *

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, + * tous les 3 tours, ça va augmenter de 1. On peut l'ecrire comme Round/N + * (les deux variables en int). + *

Le premier index est la coordonnée de la tête et les autres + * sont les coordonnées de son corps. + */ + protected ArrayList coordinate; + + /** + *

la liste est tout les effets cummulé par le Personnage. + */ + private ArrayList effects; + + /** + *

le constructor definie un arrayList pour {@link #coordinate} + * et defini n. + * + * @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) { + this.effects = new ArrayList(); + + this.coordinate = new ArrayList(); + this.coordinate.add(coordinate); + + this.n = n; } - public int getSize() { - return size; - } - - public void incrementSize(long size) { - this.size += size; - } - - public void addEffects(Effects effect) { - this.effectsList.add(effect); - } - - public ArrayList getEffects() { - return this.effectsList; - } - - public boolean haveEffect(Effects effect) { - return effectsList.contains(effect); + public int incrementRound() { + return ++this.round; } } diff --git a/src/personnages/Player.java b/src/personnages/Player.java index be388fa..ba2afb3 100644 --- a/src/personnages/Player.java +++ b/src/personnages/Player.java @@ -1,17 +1,46 @@ package personnages; +import java.util.Scanner; + public class Player extends Personnage { - public Player(int size, int[] coordinate) { - super(size, coordinate); + private int[] coordinate; + + /** + *

le constructor definie les coordonnées de la tête et defini n. + * + * @param n est une variable qui contient le nombre de + * tour avant l'augmentation de taille. + * @param coordinate est un array de 2 entiers + * qui est {x, y} + */ + public Player(int n, int[] coordinate) { + super(n, coordinate); + this.coordinate = coordinate; } - public void changeCoordinate(int keys) { + public void changeCoordinate() { + Scanner scanner = new Scanner(System.in); + char value; + + do { + value = scanner.nextLine().charAt(0); + } while (!moveCoordinate((int)value)); + + scanner.close(); + } + + public int[] getCoordinate() { + return coordinate; + } + + private boolean moveCoordinate(int keys) { switch (keys) { - case 77: Mouvement.HAUT.editCoordinate(coordinate); // w - case 73: Mouvement.BAS.editCoordinate(coordinate); // s - case 61: Mouvement.GAUCHE.editCoordinate(coordinate); // a - case 64: Mouvement.DROITE.editCoordinate(coordinate); // d - default: break; + case 119: Mouvement.HAUT.editCoordinate(coordinate); break; + case 115: Mouvement.BAS.editCoordinate(coordinate); break; + case 97: Mouvement.GAUCHE.editCoordinate(coordinate); break; + case 100: Mouvement.DROITE.editCoordinate(coordinate); break; + default: return false; } + return true; } }