mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 10:34:06 +00:00
ajout de plein d'autre fonction
This commit is contained in:
@@ -20,23 +20,29 @@ public class Map {
|
|||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
|
|
||||||
this.grid = new Object[this.largeur][this.longueur];
|
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) {
|
if (x >= 0 && x < grid[0].length && y >= 0 && y < grid.length) {
|
||||||
Object coordinate = grid[y][x];
|
Object coordinate = grid[y][x];
|
||||||
if (coordinate instanceof Items) {
|
if (coordinate instanceof Items) {
|
||||||
return ((Items) coordinate).getName();
|
return ((Items)coordinate);
|
||||||
}
|
}
|
||||||
return "null";
|
|
||||||
}
|
}
|
||||||
return "void";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Items getItems(int[] coordinate) {
|
public Items getItems(int[] coordinate) {
|
||||||
return (Items)getGrid()[coordinate[1]][coordinate[0]];
|
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() {
|
public String getStringGrid() {
|
||||||
StringBuffer stringGrid = new StringBuffer();
|
StringBuffer stringGrid = new StringBuffer();
|
||||||
|
|
||||||
@@ -51,12 +57,13 @@ public class Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addItems(Items[] items, int number) {
|
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);
|
int value = this.random.nextInt(number);
|
||||||
number -= value;
|
number -= value;
|
||||||
randomize(items[i], value);
|
randomize(items[i], value);
|
||||||
}
|
}
|
||||||
randomize(items[items.length-1], number);
|
randomize(items[lengthItems], number);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[][] getGrid() {
|
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) {
|
private void randomize(Items item, int number) {
|
||||||
for(int i = 0; i<number; i++) {
|
for(int i = 0; i<number; i++) {
|
||||||
int x = this.random.nextInt(1, this.grid[0].length);
|
int x = this.random.nextInt(1, this.grid[0].length);
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ public enum Effects {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> Modifie la valeur de N pendant 2 tours en le multipliant par 2
|
* <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
|
* <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.
|
* egal à 1 et le prochain tour quand N = 3, il sera égal à 1 (division
|
||||||
|
* d'entier).
|
||||||
*/
|
*/
|
||||||
BOOST,
|
BOOST,
|
||||||
|
|
||||||
@@ -25,5 +26,5 @@ public enum Effects {
|
|||||||
/**
|
/**
|
||||||
* <p> impossible à passer à travers.
|
* <p> impossible à passer à travers.
|
||||||
*/
|
*/
|
||||||
IMPASSABLE;
|
IMPASSABLE, Effects;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public enum Items {
|
|||||||
|
|
||||||
BODY("corps", Effects.IMPASSABLE),
|
BODY("corps", Effects.IMPASSABLE),
|
||||||
HEAD("tete", Effects.IMPASSABLE),
|
HEAD("tete", Effects.IMPASSABLE),
|
||||||
|
VOID("void", null),
|
||||||
|
|
||||||
FRAISE("fraise", Effects.INVINCIBILITY),
|
FRAISE("fraise", Effects.INVINCIBILITY),
|
||||||
ORANGE("orange", Effects.POWER),
|
ORANGE("orange", Effects.POWER),
|
||||||
|
|||||||
@@ -7,20 +7,14 @@ 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};
|
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());
|
while(!map.isGameOver(player1.getCoordinate()) || !map.isGameOver(player2.getCoordinate())) {
|
||||||
|
player1.changeCoordinate();
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ public class Personnage {
|
|||||||
*/
|
*/
|
||||||
protected ArrayList<int[]> coordinate;
|
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}
|
* <p> le constructor definie un arrayList pour {@link #coordinate}
|
||||||
* et defini n.
|
* et defini n.
|
||||||
@@ -43,8 +38,6 @@ public class Personnage {
|
|||||||
* qui sont placé par la suite dans {@link #coordinate}[0]
|
* qui sont placé par la suite dans {@link #coordinate}[0]
|
||||||
*/
|
*/
|
||||||
protected Personnage(int n, int[] coordinate) {
|
protected Personnage(int n, int[] coordinate) {
|
||||||
this.effects = new ArrayList<Effects>();
|
|
||||||
|
|
||||||
this.coordinate = new ArrayList<int[]>();
|
this.coordinate = new ArrayList<int[]>();
|
||||||
this.coordinate.add(coordinate);
|
this.coordinate.add(coordinate);
|
||||||
|
|
||||||
|
|||||||
@@ -2,43 +2,45 @@ package personnages;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
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 {
|
public class Player extends Personnage {
|
||||||
private int[] coordinate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>le constructor definie les coordonnées de la tête et defini n.
|
* <p>le constructor definie les coordonnées de la tête et defini n.
|
||||||
*
|
*
|
||||||
* @param n est une variable qui contient le nombre de
|
* @param n est une variable qui contient le nombre detour avant
|
||||||
* tour avant l'augmentation de taille.
|
* l'augmentation de taille.
|
||||||
* @param coordinate est un array de <strong>2 entiers</strong>
|
* @param coordinate est un array de <strong>2 entiers</strong> qui
|
||||||
* qui est <strong>{x, y}</strong>
|
* 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) {
|
public Player(int n, int[] coordinate) {
|
||||||
super(n, coordinate);
|
super(n, coordinate);
|
||||||
this.coordinate = coordinate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeCoordinate() {
|
public void changeCoordinate() {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
char value;
|
String value;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
value = scanner.nextLine().charAt(0);
|
value = scanner.nextLine();
|
||||||
} while (!moveCoordinate((int)value));
|
} while (!moveCoordinate((int)'w'));
|
||||||
|
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getCoordinate() {
|
public int[] getCoordinate() {
|
||||||
return coordinate;
|
return coordinate.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean moveCoordinate(int keys) {
|
private boolean moveCoordinate(int keys) {
|
||||||
switch (keys) {
|
switch (keys) {
|
||||||
case 119: Mouvement.HAUT.editCoordinate(coordinate); break;
|
case 119: Mouvement.HAUT.editCoordinate(getCoordinate()); break;
|
||||||
case 115: Mouvement.BAS.editCoordinate(coordinate); break;
|
case 115: Mouvement.BAS.editCoordinate(getCoordinate()); break;
|
||||||
case 97: Mouvement.GAUCHE.editCoordinate(coordinate); break;
|
case 97: Mouvement.GAUCHE.editCoordinate(getCoordinate()); break;
|
||||||
case 100: Mouvement.DROITE.editCoordinate(coordinate); break;
|
case 100: Mouvement.DROITE.editCoordinate(getCoordinate()); break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user