ajout de plein de fonction et suppression des anciennes classes

This commit is contained in:
2024-05-08 23:47:00 +02:00
parent 5743206062
commit 6480a90d85
7 changed files with 103 additions and 127 deletions

View File

@@ -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);
}
}

View File

@@ -3,6 +3,7 @@ package Environnements;
import java.lang.Object; import java.lang.Object;
import java.util.Random; import java.util.Random;
import Item.Effects;
import Item.Items; import Item.Items;
public class Map { public class Map {
@@ -27,15 +28,20 @@ public class Map {
if (coordinate instanceof Items) { if (coordinate instanceof Items) {
return ((Items) coordinate).getName(); 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() { public String getStringGrid() {
StringBuffer stringGrid = new StringBuffer(); StringBuffer stringGrid = new StringBuffer();
for(Object[] i : this.grid) { for(Object[] listValue : this.grid) {
for(Object value : i) { for(Object value : listValue) {
stringGrid.append(value); stringGrid.append(value);
} }
stringGrid.append("\n"); stringGrid.append("\n");

View File

@@ -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;
}
/**
* <p>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<this.debut_horizontal+this.longueur;i++){
for (int j=this.debut_vertical;j<this.debut_vertical+this.largeur;j++){
m.getGrid()[i][j]=Items.MUR;
}
}
}
}
}

View File

@@ -1,17 +1,26 @@
import java.lang.Object; import java.lang.Object;
import java.util.function.Supplier;
import Environnements.Map; import Environnements.Map;
import Item.Items; import Item.Items;
import personnages.Player;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// Items[] items = {Items.BANANE, Items.FRAISE, Items.ORANGE}; // Items[] items = {Items.BANANE, Items.FRAISE, Items.ORANGE};
Map map = new Map(10, 10); // Map map = new Map(10, 10);
map.ajoutBordure(); // map.ajoutBordure();
map.addItems(new Items[]{Items.BANANE, Items.MUR, Items.FRAISE}, 3); // map.addItems(new Items[]{Items.BANANE, Items.MUR, Items.FRAISE}, 3);
System.out.println(map.getCoordinate(1, 1)); // 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]);
} }
} }

View File

@@ -6,38 +6,52 @@ import Item.Effects;
import Item.Items; import Item.Items;
public class Personnage { public class Personnage {
/**
* <p> taille du serpent.
*/
private int size; private int size;
protected int[] coordinate; private int n; // N
protected ArrayList<int[]> CoordinateSnake; /**
private ArrayList<Effects> effectsList; * <p> 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; * <p> la liste de toute les coordonnées en fonction de N. Si N = 2,
this.size = size; * 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).
* <p> Le premier index est la coordonnée de la tête et les autres
* sont les coordonnées de son corps.
*/
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.
*
* @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<Effects>();
this.coordinate = new ArrayList<int[]>();
this.coordinate.add(coordinate);
this.n = n;
} }
public int[] getCoordinate() { public int incrementRound() {
return coordinate; return ++this.round;
}
public int getSize() {
return size;
}
public void incrementSize(long size) {
this.size += size;
}
public void addEffects(Effects effect) {
this.effectsList.add(effect);
}
public ArrayList<Effects> getEffects() {
return this.effectsList;
}
public boolean haveEffect(Effects effect) {
return effectsList.contains(effect);
} }
} }

View File

@@ -1,17 +1,46 @@
package personnages; package personnages;
import java.util.Scanner;
public class Player extends Personnage { public class Player extends Personnage {
public Player(int size, int[] coordinate) { private int[] coordinate;
super(size, 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>
*/
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) { switch (keys) {
case 77: Mouvement.HAUT.editCoordinate(coordinate); // w case 119: Mouvement.HAUT.editCoordinate(coordinate); break;
case 73: Mouvement.BAS.editCoordinate(coordinate); // s case 115: Mouvement.BAS.editCoordinate(coordinate); break;
case 61: Mouvement.GAUCHE.editCoordinate(coordinate); // a case 97: Mouvement.GAUCHE.editCoordinate(coordinate); break;
case 64: Mouvement.DROITE.editCoordinate(coordinate); // d case 100: Mouvement.DROITE.editCoordinate(coordinate); break;
default: break; default: return false;
} }
return true;
} }
} }