ajout de plein d'autre fonction

This commit is contained in:
2024-05-09 11:10:43 +02:00
parent 6480a90d85
commit 83ab978dda
6 changed files with 51 additions and 45 deletions

View File

@@ -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 ((Items)coordinate);
}
return "null";
}
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<lengthItems; i++) {
int value = this.random.nextInt(number);
number -= value;
randomize(items[i], value);
}
randomize(items[items.length-1], number);
randomize(items[lengthItems], number);
}
public Object[][] getGrid() {
@@ -73,6 +80,14 @@ public class Map {
}
}
private void fillGrid() {
for(int i = 0; i < this.grid.length; i++) {
for(int k = 0; k < this.grid[0].length; k++) {
this.grid[i][k] = Items.VOID;
}
}
}
private void randomize(Items item, int number) {
for(int i = 0; i<number; i++) {
int x = this.random.nextInt(1, this.grid[0].length);

View File

@@ -12,8 +12,9 @@ public enum Effects {
/**
* <p> Modifie la valeur de N pendant 2 tours en le multipliant par 2
* <p> <strong>Exemple : </strong> si N = 2, il va être *2 donc N sera
* egal à 4 et le prochain tour quand N = 3, il sera égal à 6.
* <p> <strong>Exemple : </strong> 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 {
/**
* <p> impossible à passer à travers.
*/
IMPASSABLE;
IMPASSABLE, Effects;
}

View File

@@ -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),

View File

@@ -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);
Player player1 = new Player(n, new int[]{1, 1});
Player player2 = new Player(n, new int[]{9, 9});
// map.ajoutBordure();
// map.addItems(new Items[]{Items.BANANE, Items.MUR, Items.FRAISE}, 3);
// 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();
}
}
}

View File

@@ -28,11 +28,6 @@ public class Personnage {
*/
protected ArrayList<int[]> coordinate;
/**
* <p> la liste est tout les effets cummulé par le Personnage.
*/
private ArrayList<Effects> effects;
/**
* <p> 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<Effects>();
this.coordinate = new ArrayList<int[]>();
this.coordinate.add(coordinate);

View File

@@ -2,43 +2,45 @@ package personnages;
import java.util.Scanner;
/**
* <p>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;
/**
* <p>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 <strong>2 entiers</strong>
* qui est <strong>{x, y}</strong>
* @param n est une variable qui contient le nombre detour avant
* l'augmentation de taille.
* @param coordinate est un array de <strong>2 entiers</strong> qui
* est représenté comme <strong>{x, y}</strong> 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;