mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 12:34:07 +00:00
mise en place d'un runner pour windows (UTF-8)
This commit is contained in:
17
run.bat
Normal file
17
run.bat
Normal file
@@ -0,0 +1,17 @@
|
||||
@echo off
|
||||
|
||||
set "error_file=error.txt"
|
||||
|
||||
chcp 65001
|
||||
make 2> %error_file%
|
||||
|
||||
for %%A in ("%error_file%") do set "errror_size=%%~zA"
|
||||
|
||||
if %errror_size% gtr 0 (
|
||||
@echo Vous avez besoin d'installer make ou allez sur le repertoire ou contient Makefile pour lancer correctement le programme.
|
||||
)
|
||||
|
||||
del /Q %error_file%
|
||||
|
||||
pause > null
|
||||
exit
|
||||
@@ -14,6 +14,7 @@ public class Personnage {
|
||||
private int round;
|
||||
private int size = 0;
|
||||
private String name;
|
||||
private String effect;
|
||||
|
||||
/**
|
||||
* <p> la liste de toute les coordonnées en fonction de N. Si N = 2,
|
||||
@@ -133,11 +134,19 @@ public class Personnage {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getEffects(Object item) {
|
||||
return new String();
|
||||
}
|
||||
|
||||
public Mouvements getMouvement(Integer keys) {
|
||||
switch (keys) {
|
||||
case 0x77: return Mouvements.HAUT; // w
|
||||
case 0x77: case 0x7A: return Mouvements.HAUT; // w ou z
|
||||
case 0x73: return Mouvements.BAS; // s
|
||||
case 0x61: return Mouvements.GAUCHE; // a
|
||||
case 0x61: case 0x71: return Mouvements.GAUCHE; // a
|
||||
case 0x64: return Mouvements.DROITE; // d
|
||||
case null: return null;
|
||||
default: return null;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import Characters.Personnage;
|
||||
import Characters.Players;
|
||||
import Display.Terminal;
|
||||
import Display.TerminalDisplay;
|
||||
import Environnement.Map;
|
||||
import Objects.Fruits;
|
||||
import Objects.Items;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Personnage.n = 2;
|
||||
Personnage.n = 4;
|
||||
|
||||
Map map = new Map(30, 30);
|
||||
|
||||
Personnage[] personnages = new Personnage[] {
|
||||
new Players("d", new int[] {1, 1}),
|
||||
new Players("e", new int[] {28, 28})
|
||||
new Players("Phillipe", new int[] {1, 1}),
|
||||
new Players("Edouard", new int[] {28, 28})
|
||||
};
|
||||
|
||||
Terminal.edges = true;
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Terminal {
|
||||
private static Scanner scanner;
|
||||
private static Map map;
|
||||
private static Personnage[] personnages;
|
||||
private int round = 0;
|
||||
|
||||
public static boolean edges = false;
|
||||
|
||||
@@ -86,7 +87,7 @@ public class Terminal {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
private void run() {
|
||||
TerminalDisplay.clearTerminal();
|
||||
if (edges) map.addEdges();
|
||||
boolean isNotGameOver = true;
|
||||
@@ -99,11 +100,17 @@ public class Terminal {
|
||||
for (i = 0; i<personnages.length; i++) {
|
||||
Personnage personnage = personnages[i];
|
||||
|
||||
System.out.println("\nJoueur " + (i+1) + " : " + personnage.getName());
|
||||
int[] coordinate = personnage.getPrimaryCoordinate();
|
||||
|
||||
System.out.println("Round : " + this.round + " | N : " + Personnage.n);
|
||||
System.out.println(" Joueur " + (i+1) + " : " + personnage.getName() +
|
||||
" (" + coordinate[0]+", "+ coordinate[1] +") | size : " + personnage.getSize());
|
||||
|
||||
isNotGameOver = instancePersonnage(personnage);
|
||||
if(isNotGameOver) placePersonnages(personnages);
|
||||
else break;
|
||||
}
|
||||
this.round++;
|
||||
}
|
||||
System.out.println("Le joueur " + (i+1) + " à perdu !");
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TerminalDisplay {
|
||||
|
||||
private static void printSnake(Snake item, Personnage[] personnages, int x, int y) {
|
||||
switch (item) {
|
||||
case BODY: System.out.print(" \uF353 "); break;
|
||||
case BODY: System.out.print(" = "); break;
|
||||
case HEAD: printHead(personnages, x, y); break;
|
||||
}
|
||||
}
|
||||
@@ -116,17 +116,28 @@ public class TerminalDisplay {
|
||||
if (x > 0) isWall[2] = map[y][x - 1] == Items.WALL; else isWall[2] = false;
|
||||
if (x < map[0].length - 1) isWall[3] = map[y][x + 1] == Items.WALL; else isWall[3] = false;
|
||||
|
||||
if (isWall[0] && isWall[1] && isWall[2] && isWall[3]) {System.out.print("\u2550\u256C\u2550");return;}
|
||||
else if (isWall[0] && isWall[1] && isWall[3]) {System.out.print("\u2560");return;}
|
||||
else if (isWall[0] && isWall[1] && isWall[2]) {System.out.print("\u2563");return;}
|
||||
else if (isWall[0] && isWall[2] && isWall[3]) {System.out.print("\u2550\u2569\u2550");return;}
|
||||
else if (isWall[1] && isWall[2] && isWall[3]) {System.out.print("\u2550\u2566\u2550");return;}
|
||||
else if (isWall[0] && isWall[1]) {System.out.print("\u2551");return;}
|
||||
else if (isWall[2] && isWall[3]) {System.out.print("\u2550\u2550\u2550");return;}
|
||||
else if (isWall[0] && isWall[2]) {System.out.print("\u255D ");return;}
|
||||
else if (isWall[0] && isWall[3]) {System.out.print("\u255A");return;}
|
||||
else if (isWall[1] && isWall[2]) {System.out.print("\u2557 ");return;}
|
||||
else if (isWall[1] && isWall[3]) {System.out.print("\u2554");return;}
|
||||
else {System.out.print("\u2550\u256C\u2550");return;}
|
||||
System.out.print(whichWall(isWall));
|
||||
}
|
||||
|
||||
private static String whichWall(boolean[] isWall) {
|
||||
String positionWall = new String();
|
||||
|
||||
if (isWall[0] && isWall[1] && isWall[2] && isWall[3]) positionWall = "\u2550\u256C\u2550";
|
||||
|
||||
else if (isWall[0] && isWall[1] && isWall[3]) positionWall = "\u2560";
|
||||
else if (isWall[0] && isWall[1] && isWall[2]) positionWall = "\u2563";
|
||||
else if (isWall[0] && isWall[2] && isWall[3]) positionWall = "\u2550\u2569\u2550";
|
||||
else if (isWall[1] && isWall[2] && isWall[3]) positionWall = "\u2550\u2566\u2550";
|
||||
|
||||
else if (isWall[0] && isWall[1]) positionWall = "\u2551";
|
||||
else if (isWall[2] && isWall[3]) positionWall = "\u2550\u2550\u2550";
|
||||
else if (isWall[0] && isWall[2]) positionWall = "\u255D ";
|
||||
else if (isWall[0] && isWall[3]) positionWall = "\u255A";
|
||||
else if (isWall[1] && isWall[2]) positionWall = "\u2557 ";
|
||||
else if (isWall[1] && isWall[3]) positionWall = "\u2554";
|
||||
|
||||
else positionWall = "\u2550\u256C\u2550";
|
||||
|
||||
return positionWall;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
package Display;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import Characters.Personnage;
|
||||
import Characters.Players;
|
||||
import Characters.Robot;
|
||||
import Environnement.Map;
|
||||
import Objects.Fruits;
|
||||
import Objects.Items;
|
||||
import Objects.Snake;
|
||||
|
||||
public class Test2 {
|
||||
private static Scanner scanner = new Scanner(System.in);
|
||||
private static String name = new String();
|
||||
|
||||
private static Map map;
|
||||
|
||||
/**
|
||||
* <p> Cette fonction est uniquement destiné pour la classe
|
||||
* Players pour recuperer l'input dans le terminal.
|
||||
* @param scanner
|
||||
* @param player
|
||||
* @return il retourne int qui est le char en ascii
|
||||
*/
|
||||
private static int getInput(Scanner scanner, Players player) {
|
||||
String value = new String();
|
||||
Integer input = null;
|
||||
|
||||
do {
|
||||
value = scanner.nextLine();
|
||||
input = player.changeCoordinate(value);
|
||||
}while(player.getMouvement(input) == null);
|
||||
|
||||
return input.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> print toute la map.
|
||||
* @param map
|
||||
*/
|
||||
private static void printMap(Map map) {
|
||||
Object[][] mapObjects = map.getGrid();
|
||||
|
||||
for (int i = 0; i<mapObjects.length; i++) {
|
||||
for(int k = 0; k<mapObjects[0].length; k++) {
|
||||
if (mapObjects[i][k] instanceof Items) System.out.print(((Items)mapObjects[i][k]).getName() + " ");
|
||||
if (mapObjects[i][k] instanceof Fruits) System.out.print(((Fruits)mapObjects[i][k]).getName() + " ");
|
||||
if (mapObjects[i][k] instanceof Snake) System.out.print(((Snake)mapObjects[i][k]).getName() + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printWall(Map map) {
|
||||
Object[][] mapObjects = map.getGrid();
|
||||
|
||||
// for
|
||||
}
|
||||
|
||||
private static void printPersonnages(Personnage[] personnages) {
|
||||
for(int i = 0; i<personnages.length; i++) {
|
||||
int[] coordinate = personnages[i].getPrimaryCoordinate();
|
||||
System.out.println("Joueur " + (i+1) + " sont aux coordonnées : {" + coordinate[0] + "," + coordinate[1] + "}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cette fonction clear le terminal et le remet en
|
||||
* haut a gauche de la ligne.
|
||||
*/
|
||||
private static void clearTerminal() {
|
||||
System.out.println("\u001b[2J \u001b[H");
|
||||
}
|
||||
|
||||
private static void placePersonnages(Personnage[] personnages) {
|
||||
for(Personnage personnage : personnages) {
|
||||
map.placePersonnages(personnage);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean playerRound(Players player) {
|
||||
printMap(map);
|
||||
|
||||
int[] latestCoordinate = player.keepLatestCoordinate();
|
||||
int input = getInput(scanner, player);
|
||||
player.moveCoordinate(input);
|
||||
|
||||
if(map.isGameOver(input, player)) {
|
||||
System.out.println("GameOver");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(player.isIncreaseSize()) player.increaseSnake(latestCoordinate);
|
||||
|
||||
clearTerminal();
|
||||
// map.clearMap();
|
||||
player.incrementRound();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean robotRound(Robot robot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean instancePersonnage(Personnage personnage) {
|
||||
if (personnage instanceof Players) {
|
||||
// tour du Player
|
||||
return playerRound((Players)personnage);
|
||||
}
|
||||
|
||||
if (personnage instanceof Robot) {
|
||||
// tour du robot
|
||||
return robotRound((Robot)personnage);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void sleepTerminal(long value) {
|
||||
try {Thread.sleep(value);}
|
||||
catch (InterruptedException e){ e.printStackTrace();}
|
||||
}
|
||||
|
||||
public static void run(Personnage[] personnages, Map m, int n) {
|
||||
boolean isNotGameOver = true;
|
||||
map = m;
|
||||
|
||||
// place les personnages dans la grille.
|
||||
placePersonnages(personnages);
|
||||
// print dans le terminal.
|
||||
printPersonnages(personnages);
|
||||
|
||||
while(isNotGameOver) {
|
||||
for (int i = 0; i<personnages.length; i++) {
|
||||
System.out.println("\nJoueur " + (i+1) + " :");
|
||||
isNotGameOver = instancePersonnage(personnages[i]);
|
||||
if (isNotGameOver) placePersonnages(personnages);
|
||||
else break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("bien joué!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user