diff --git a/src/Environnements/Map.java b/src/Environnements/Map.java index 53ba3e1..f084c92 100644 --- a/src/Environnements/Map.java +++ b/src/Environnements/Map.java @@ -20,23 +20,29 @@ public class Map { this.random = new Random(); this.grid = new Object[this.largeur][this.longueur]; + this.fillGrid(); } - public String getCoordinate(int x, int y) { + 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).getName(); - } - return "null"; + return ((Items)coordinate); + } } - return "void"; + return null; } public Items getItems(int[] coordinate) { return (Items)getGrid()[coordinate[1]][coordinate[0]]; } + public boolean isGameOver(int[] coordinate) { + if (getCoordinate(longueur, largeur) != null && + getCoordinate(longueur, largeur).getEffects() == Effects.IMPASSABLE) return true; + return false; + } + public String getStringGrid() { StringBuffer stringGrid = new StringBuffer(); @@ -51,12 +57,13 @@ public class Map { } public void addItems(Items[] items, int number) { - for(int i = 0; i<(items.length-1); i++) { + int lengthItems = (items.length-1); + for(int i = 0; i Modifie la valeur de N pendant 2 tours en le multipliant par 2 - *

Exemple : si N = 2, il va être *2 donc N sera - * egal à 4 et le prochain tour quand N = 3, il sera égal à 6. + *

Exemple : si N = 2, il va être /2 donc N sera + * egal à 1 et le prochain tour quand N = 3, il sera égal à 1 (division + * d'entier). */ BOOST, @@ -25,5 +26,5 @@ public enum Effects { /** *

impossible à passer à travers. */ - IMPASSABLE; + IMPASSABLE, Effects; } diff --git a/src/Item/Items.java b/src/Item/Items.java index 60e0b4b..c63da9b 100644 --- a/src/Item/Items.java +++ b/src/Item/Items.java @@ -8,6 +8,7 @@ public enum Items { BODY("corps", Effects.IMPASSABLE), HEAD("tete", Effects.IMPASSABLE), + VOID("void", null), FRAISE("fraise", Effects.INVINCIBILITY), ORANGE("orange", Effects.POWER), diff --git a/src/Main.java b/src/Main.java index 0919de1..4a839e2 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,20 +7,14 @@ import personnages.Player; public class Main { public static void main(String[] args) { - // Items[] items = {Items.BANANE, Items.FRAISE, Items.ORANGE}; + int n = 2; + Map map = new Map(10, 10); - // Map map = new Map(10, 10); - - // map.ajoutBordure(); - // map.addItems(new Items[]{Items.BANANE, Items.MUR, Items.FRAISE}, 3); + Player player1 = new Player(n, new int[]{1, 1}); + Player player2 = new Player(n, new int[]{9, 9}); - // System.out.println(map.getStringGrid()); - - Player player = new Player(0, new int[]{1, 1}); - System.out.println("donne moi w s d q"); - player.changeCoordinate(); - - - System.out.println(player.getCoordinate()[0] + " " + player.getCoordinate()[1]); + while(!map.isGameOver(player1.getCoordinate()) || !map.isGameOver(player2.getCoordinate())) { + player1.changeCoordinate(); + } } } diff --git a/src/personnages/Personnage.java b/src/personnages/Personnage.java index 92ddda4..df5d469 100644 --- a/src/personnages/Personnage.java +++ b/src/personnages/Personnage.java @@ -28,11 +28,6 @@ public class Personnage { */ 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. @@ -43,8 +38,6 @@ public class Personnage { * 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); diff --git a/src/personnages/Player.java b/src/personnages/Player.java index ba2afb3..4201cf2 100644 --- a/src/personnages/Player.java +++ b/src/personnages/Player.java @@ -2,43 +2,45 @@ package personnages; import java.util.Scanner; +/** + *

la classe Player est la classe principale pour l'utilisation de toute + * input et output que l'utilisateur peut faire. + */ public class Player extends Personnage { - 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} + * @param n est une variable qui contient le nombre detour avant + * l'augmentation de taille. + * @param coordinate est un array de 2 entiers qui + * 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); - this.coordinate = coordinate; } public void changeCoordinate() { Scanner scanner = new Scanner(System.in); - char value; + String value; do { - value = scanner.nextLine().charAt(0); - } while (!moveCoordinate((int)value)); + value = scanner.nextLine(); + } while (!moveCoordinate((int)'w')); scanner.close(); } public int[] getCoordinate() { - return coordinate; + return coordinate.get(0); } private boolean moveCoordinate(int keys) { switch (keys) { - 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; + 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; } return true;