mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 09:34:06 +00:00
changement de l'ordre des fichiers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package Connexion;
|
||||
package connexion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package Environnements;
|
||||
package environnements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import Objets.Effects;
|
||||
import Objets.Items;
|
||||
import Personnages.Personnage;
|
||||
import Personnages.Snake;
|
||||
import object.*;
|
||||
import personnages.*;
|
||||
|
||||
|
||||
/**
|
||||
* cette classe est la classe qui cree et genere
|
||||
@@ -75,7 +74,7 @@ public class Map {
|
||||
}
|
||||
|
||||
public boolean isGameOver(int[] coordinate) {
|
||||
return coordinate[0] < 0 || coordinate[0] >= this.grid[coordinate[1]].length ||
|
||||
return coordinate[0] < 0 || coordinate[0] >= this.grid[0].length ||
|
||||
coordinate[1] < 0 || coordinate[1] >= this.grid.length;
|
||||
}
|
||||
|
||||
@@ -199,7 +198,8 @@ public class Map {
|
||||
*/
|
||||
public void deleteItems(int[] coordinate) {
|
||||
for(int i = 0; i<this.coordinateItems.size(); i++) {
|
||||
if (this.coordinateItems.get(i) == coordinate) {
|
||||
int[] itemCoordinate = this.coordinateItems.get(i);
|
||||
if (itemCoordinate[0] == coordinate[0] && itemCoordinate[1] == coordinate[1]) {
|
||||
this.coordinateItems.remove(i);
|
||||
this.ObjectItems.remove(i);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import Display.Terminal;
|
||||
import Environnements.Map;
|
||||
import Objets.Items;
|
||||
import Personnages.Personnage;
|
||||
import Personnages.Player;
|
||||
import environnements.Map;
|
||||
import game.Terminal;
|
||||
import personnages.Personnage;
|
||||
import personnages.Player;
|
||||
import tests.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Personnage.n = 2;
|
||||
|
||||
Map map = new Map(12, 30);
|
||||
|
||||
map.addObjects(Items.FRAISE, 5, 5);
|
||||
|
||||
Personnage[] personnages = new Personnage[] {
|
||||
new Player(new int[] {0, 0}, "Phillipe")
|
||||
new Player(new int[] {0, 0}, "Philippe Etchebest"),
|
||||
new Player(new int[] {19, 19}, "Luke Skywalker")
|
||||
};
|
||||
|
||||
Map map = new Map(20, 20);
|
||||
|
||||
new Terminal(map, personnages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package Personnages;
|
||||
package personnages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import Objets.Effects;
|
||||
import object.*;
|
||||
|
||||
/**
|
||||
* Cette classe est la primitive des classes
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package Personnages;
|
||||
package personnages;
|
||||
|
||||
import object.*;
|
||||
|
||||
/**
|
||||
* la classe Player a comme classe parent {@link Personnage}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package Personnages;
|
||||
package personnages;
|
||||
|
||||
public class Robot extends Personnage {
|
||||
public Robot(int[] coordinate) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package Display;
|
||||
package display;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import Environnements.Map;
|
||||
import Objets.Items;
|
||||
import Personnages.Personnage;
|
||||
import Personnages.Snake;
|
||||
import object.*;
|
||||
import personnages.*;
|
||||
|
||||
public class Display {
|
||||
/**
|
||||
@@ -129,8 +127,8 @@ public class Display {
|
||||
|
||||
if (isHead[0]) {System.out.print(" \u21E9 ");return;}
|
||||
else if (isHead[1]) {System.out.print(" \u21E7 ");return;}
|
||||
else if (isHead[2]) {System.out.print("\u21E8 ");return;}
|
||||
else if (isHead[3]) {System.out.print(" \u21E6");return;}
|
||||
else if (isHead[2]) {System.out.print(" \u21E8");return;}
|
||||
else if (isHead[3]) {System.out.print("\u21E6 ");return;}
|
||||
}
|
||||
}
|
||||
System.out.print(" \u25CF ");
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package Display;
|
||||
package game;
|
||||
|
||||
import display.*;
|
||||
import personnages.*;
|
||||
import environnements.*;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import Environnements.Map;
|
||||
import Objets.Effects;
|
||||
import Objets.Items;
|
||||
import Personnages.Mouvements;
|
||||
import Personnages.Personnage;
|
||||
import Personnages.Player;
|
||||
import Personnages.Robot;
|
||||
|
||||
public class Terminal {
|
||||
private int round = 0;
|
||||
|
||||
@@ -74,11 +70,11 @@ public class Terminal {
|
||||
* @return
|
||||
*/
|
||||
private static boolean playerRound(Player player) {
|
||||
int input = getInput(player);
|
||||
player.moveCoordinate(input);
|
||||
player.moveCoordinate(getInput(player));
|
||||
|
||||
int[] coordinate = player.getHeadCoordinate();
|
||||
if(map.isGameOver(player.getHeadCoordinate()) || player.applyEffects(map.getEffect(coordinate))) return true;
|
||||
if(map.isGameOver(coordinate) || player.applyEffects(map.getEffect(coordinate))) return true;
|
||||
map.deleteItems(coordinate);
|
||||
|
||||
player.increaseRound();
|
||||
return false;
|
||||
@@ -121,7 +117,7 @@ public class Terminal {
|
||||
int i = 0;
|
||||
|
||||
while(!isGameOver) {
|
||||
for (i = 0; i<personnages.length; i++) {
|
||||
for (i = 0;i<personnages.length; i++) {
|
||||
Personnage personnage = personnages[i];
|
||||
Display.clearTerminal();
|
||||
|
||||
@@ -137,6 +133,7 @@ public class Terminal {
|
||||
if(!isGameOver) placePersonnages(personnages);
|
||||
else break;
|
||||
|
||||
System.out.println(1);
|
||||
map.clearMap();
|
||||
}
|
||||
this.round++;
|
||||
@@ -1,4 +1,4 @@
|
||||
package Objets;
|
||||
package object;
|
||||
|
||||
/**
|
||||
* cette enumérateur {@link Effects} contient tout les effets
|
||||
@@ -1,4 +1,4 @@
|
||||
package Objets;
|
||||
package object;
|
||||
|
||||
public enum Items {
|
||||
WALL("WALL", Effects.IMPASSABLE),
|
||||
@@ -1,11 +1,14 @@
|
||||
package Personnages;
|
||||
package object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Cet enumerateur prend en charge tout les mouvements possible
|
||||
* pour le serpent, il a uniquement la possibilité de se déplacer
|
||||
* grâce a {@link Mouvements} pour la classe Player et Robot.
|
||||
*/
|
||||
public enum Mouvements {
|
||||
@SuppressWarnings("unused")
|
||||
public enum Mouvements implements Serializable {
|
||||
/**
|
||||
* HAUT prend comme coordonnée (0, -1) pour se déplacer.
|
||||
* @param x = 0
|
||||
@@ -1,6 +1,4 @@
|
||||
package Personnages;
|
||||
|
||||
import Objets.Effects;
|
||||
package object;
|
||||
|
||||
public enum Snake {
|
||||
HEAD("TETE", Effects.IMPASSABLE),
|
||||
38
src/tests/MapTest.java
Normal file
38
src/tests/MapTest.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package tests;
|
||||
|
||||
import display.Display;
|
||||
import environnements.Map;
|
||||
import object.Items;
|
||||
import personnages.Personnage;
|
||||
import personnages.Player;
|
||||
|
||||
public class MapTest {
|
||||
public static void creationMap() {
|
||||
Map map = new Map(30, 30);
|
||||
map.addObjects(Items.FRAISE, 29, 29);
|
||||
map.placeObjects();
|
||||
|
||||
Display.printMap(map.addEdges());
|
||||
}
|
||||
|
||||
public static void drawMap() {
|
||||
Map map = new Map(30, 30);
|
||||
Display.printMap(map.addEdges(), null);
|
||||
}
|
||||
|
||||
public static void placePersonnageMap() {
|
||||
Map map = new Map(30, 30);
|
||||
map.placePersonnages(new Player(new int[]{1, 1}, "null"));
|
||||
|
||||
Display.printMap(map.addEdges(), new Personnage[] {new Player(new int[]{1, 1}, "null")});
|
||||
}
|
||||
|
||||
public static void effects() {
|
||||
Map map = new Map(5, 1);
|
||||
Player player = new Player(new int[] {0, 0}, "null");
|
||||
map.addObjects(Items.FRAISE, 0, 0);
|
||||
|
||||
player.applyEffects(map.getEffect(player.getHeadCoordinate()));
|
||||
System.out.println(player.getSize());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import Objets.Effects;
|
||||
import Objets.Items;
|
||||
import Display.Display;
|
||||
import Environnements.Map;
|
||||
import Personnages.Mouvements;
|
||||
import Personnages.Personnage;
|
||||
import Personnages.Player;
|
||||
package tests;
|
||||
|
||||
public class Tests {
|
||||
import object.Effects;
|
||||
import object.Mouvements;
|
||||
import personnages.Personnage;
|
||||
import personnages.Player;
|
||||
|
||||
public class PersonnageTest {
|
||||
public static void avancerPersonnage() {
|
||||
Player player = new Player(new int[]{1, 1}, "test");
|
||||
|
||||
@@ -36,30 +35,4 @@ public class Tests {
|
||||
|
||||
System.out.println(player.getCoordinate());
|
||||
}
|
||||
|
||||
public static void creationMap() {
|
||||
Map map = new Map(30, 30);
|
||||
map.addObjects(Items.FRAISE, 29, 29);
|
||||
map.placeObjects();
|
||||
|
||||
Display.printMap(map.addEdges());
|
||||
}
|
||||
|
||||
public static void drawMap() {
|
||||
Map map = new Map(30, 30);
|
||||
Display.printMap(map.addEdges(), null);
|
||||
}
|
||||
|
||||
public static void placePersonnageMap() {
|
||||
Map map = new Map(30, 30);
|
||||
map.placePersonnages(new Player(new int[]{1, 1}, "null"));
|
||||
|
||||
Display.printMap(map.addEdges(), new Personnage[] {new Player(new int[]{1, 1}, "null")});
|
||||
}
|
||||
|
||||
public static void effects() {
|
||||
Map map = new Map(5, 1);
|
||||
Player player = new Player(new int[] {0, 0}, "null");
|
||||
map.addObjects(Items.FRAISE, 1, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user