diff --git a/src/Characters/Players.java b/src/Characters/Players.java index 311566e..b7af422 100644 --- a/src/Characters/Players.java +++ b/src/Characters/Players.java @@ -4,7 +4,7 @@ public class Players extends Personnage { public Players(String name, int[] coordinate) { super(name, coordinate); } - + public Integer changeCoordinate(String input) { if (input.length() > 0) { return (int)input.charAt(0); diff --git a/src/Characters/Robot.java b/src/Characters/Robot.java index 6d09776..b0bab4f 100644 --- a/src/Characters/Robot.java +++ b/src/Characters/Robot.java @@ -1,8 +1,6 @@ package Characters; import java.util.ArrayList; -//import java.util.Random; - import javax.swing.JOptionPane; import Environnement.*; @@ -10,18 +8,32 @@ import Objects.Effects; public class Robot extends Personnage { - public Robot(String name, int[] coordinate) { + Map m; + Mouvements move; + + public Robot(String name, int[] coordinate,Map m) { super(name, coordinate); + this.m=m; + move=this.compare(this.getCoordinate().get(0), this.choix().get(0)); + jouer(m); } - public Mouvements jouer(Map m){ - Mouvements move=this.compare(this.getCoordinate().get(0), this.choix(m).get(0)); - return move; + public String jouer(Map m){ + if (this.move==Mouvements.HAUT){ + return "U"; + }else if(this.move==Mouvements.BAS){ + return "D"; + }else if(this.move==Mouvements.GAUCHE){ + return "L"; + }else if(this.move==Mouvements.DROITE){ + return "R"; + } + return "Problème"; } - public boolean estPossible(int x,int y,Map m){ - JOptionPane.showInputDialog((m.getGrid().length+" "+ m.getGrid()[0].length).toString()); - Object [][] grille=new Object[][] {m.getGrid()}; + public boolean estPossible(int x,int y){ + JOptionPane.showInputDialog((this.m.getGrid().length+" "+ this.m.getGrid()[0].length).toString()); + Object [][] grille=new Object[][] {this.m.getGrid()}; if (grille[x][y]==Effects.IMPASSABLE){ return false; } @@ -33,33 +45,33 @@ public class Robot extends Personnage { return t; } - public ArrayList coupsPossibles(int [] co,Map m) { + public ArrayList coupsPossibles(int [] co) { ArrayList coupsValables=new ArrayList (); - if (this.estPossible(co[0]+1,co[1], m)){ + if (this.estPossible(co[0]+1,co[1])){ coupsValables.add(creerTab(co[0]+1, co[1])); - }else if (this.estPossible(co[0],co[1]+1, m)){ + }else if (this.estPossible(co[0],co[1]+1)){ coupsValables.add(creerTab(co[0], co[1]+1)); - }else if (this.estPossible(co[0]-1,co[1], m)){ + }else if (this.estPossible(co[0]-1,co[1])){ coupsValables.add(creerTab(co[0]-1, co[1])); - }else if (this.estPossible(co[0],co[1]-1, m)){ + }else if (this.estPossible(co[0],co[1]-1)){ coupsValables.add(creerTab(co[0], co[1]-1)); } return coupsValables; } - public ArrayList casesAutour(Map m){ - ArrayList t =this.coupsPossibles(this.getCoordinate().get(0),m); + public ArrayList casesAutour(){ + ArrayList t =this.coupsPossibles(this.getCoordinate().get(0)); ArrayList t2 = new ArrayList<> (); for (int i=0;i choix(Map m){ - ArrayList cases=casesAutour(m); + public ArrayList choix(){ + ArrayList cases=casesAutour(); ArrayList > w=new ArrayList<>(); for (int i=0;i max=w.get(0); for (ArrayList e :w){ diff --git a/src/Connexion/Channel.java b/src/Connexion/Channel.java index ba4c279..4f0619b 100644 --- a/src/Connexion/Channel.java +++ b/src/Connexion/Channel.java @@ -1,23 +1,63 @@ package Connexion; -import Connexion.Reseau; -import display.*; +import java.util.ArrayList; -public class Channel extends Reseau{ +import javax.swing.JOptionPane; + +import Environnement.*; +import Characters.*; +import display.TerminalChannel; + +public class Channel{ + Reseau reseau; + ArrayList personnages; int numJoueur; + TerminalChannel term; + Map m; - public Channel(String channel, Terminal t, int numJoueur){ - super(channel); - this.numJoueur=numJoueur; + public Channel(Reseau r, ArrayList p, int j,TerminalChannel term,Map m){ + this.reseau=r; + this.personnages=p; + this.numJoueur=j; + this.term=term; + this.m=m; } - public void partie(Terminal t){ - boolean partie=true; - while(partie){ - if (t.getRound()%2!=this.numJoueur){ - this.getNewArrayListContent(); + public String typePersonnage(int i){ + if (i>=0 && i 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 + */ + + public boolean playerRound(Players player) { + TerminalDisplay.printMap(map, personnages); + // TerminalDisplay.printMapType(map); + + int[] latestCoordinate = player.keepLatestCoordinate(); + int input=getInput(null); + player.moveCoordinate(input); + + if(map.isGameOver(input, player)) {TerminalDisplay.clearTerminal(); System.out.println("GameOver"); return false;} + if(player.isIncreaseSize()) player.increaseSnake(latestCoordinate); + + TerminalDisplay.clearTerminal(); + map.clearMap(edges); + player.incrementRound(); + return true; + } + + private static boolean robotRound(Robot robot) { + return false; + } + + private 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; + } + + public boolean run() { + TerminalDisplay.clearTerminal(); + if (edges) map.addEdges(); + boolean isNotGameOver = true; + int i = 0; + + // place les personnages dans la grille. + placePersonnages(personnages); + + while(isNotGameOver) { + for (i = 0; i