diff --git a/src/main/Joueur.java b/src/main/Joueur.java index 1c72c1e908ea2dfb156638cfe8de921f36c5121d..c71a531badd242e0d0b899f286e3f487e5b81e59 100644 --- a/src/main/Joueur.java +++ b/src/main/Joueur.java @@ -15,9 +15,13 @@ public class Joueur { private static int cptJoueur = 1; private boolean win = false; private List<Region> royaume; + public int xCamp; + public int yCamp; - public Joueur (String nom) { + public Joueur (String nom, int xCamp, int yCamp) { this.nomJoueur = nom; + this.xCamp = xCamp; + this.yCamp = yCamp; this.numJoueur = cptJoueur; this.armee = new ArrayList<Unite>(); this.paJoueur = 5; diff --git a/src/main/Main.java b/src/main/Main.java index 9dd3e40e0249ddffabee76ad1f674a58015694b2..a2e631abf61d5829d9fb9fbedc6fbfb04cef03f1 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -5,7 +5,9 @@ import java.util.Scanner; import units.Paysant; public class Main { - private static Joueur winner = new Joueur("Winner"); + private static Joueur joueur1 = new Joueur("Joueur 1", 5, 15); + private static Joueur joueur2 = new Joueur("Joueur 2", 25, 15); + private Joueur winner = null; private int actionPoint; public static void main(String[] args) { @@ -17,23 +19,27 @@ public class Main { Plateau plateau = new Plateau(); - int x = 11; - int y = 10; - - - plateau.getCase(x, y).setUnite(new Paysant(x, y, plateau, winner)); - winner.getArmee().get(0).getPlateau().getRegion(0,0).changeToCamp(); + plateau.getCase(joueur1.xCamp, joueur1.yCamp).setUnite(new Paysant(joueur1.xCamp, joueur1.yCamp, plateau, joueur1)); + plateau.getCase(joueur2.xCamp, joueur2.yCamp).setUnite(new Paysant(joueur2.xCamp, joueur2.yCamp, plateau, joueur2)); + joueur1.getArmee().get(0).getPlateau().getRegion(joueur1.xCamp-1,joueur1.yCamp-1).changeToCamp(); + joueur2.getArmee().get(0).getPlateau().getRegion(joueur2.xCamp,joueur2.yCamp).changeToCamp(); Affichage.affichage(plateau); - while(y<30) { - winner.getArmee().get(0).move(deplacement()); + while(true!=false) { + joueur1.getArmee().get(0).move(deplacement()); + //System.out.println(winner.getArmee().get(0).getPlateau().getRegion(0, 0).); System.out.println('\n'); + System.out.println(joueur1.getArmee().get(0).getX()); //winner.getArmee().get(0).teleporte(); Affichage.affichage(plateau); + + //joueur2.getArmee().get(0).move(deplacement()); + + //Affichage.affichage(plateau); } - Menu(); + //Menu(); - plateau.getCase(12, 0); - Affichage.affichage(plateau); + //plateau.getCase(12, 0); + //Affichage.affichage(plateau); //Menu(); } diff --git a/src/main/Plateau.java b/src/main/Plateau.java index c9c05b50141f66cd6cd62de56b766dd55ae5f99d..752a7d10a462e4da875ea6a63f2622b7928eb01d 100644 --- a/src/main/Plateau.java +++ b/src/main/Plateau.java @@ -9,7 +9,7 @@ public class Plateau { public Plateau() { Random random = new Random(); - this.plateau = new Region[6][6]; + this.plateau = new Region[7][7]; for (int i = 0; i < plateau.length; i++) { for (int j = 0; j < plateau[0].length; j++) { plateau[i][j] = new Region(); @@ -23,9 +23,15 @@ public class Plateau { this.getCase(rd1, rd2).setItem(new Crown(this.getCase(0, 0))); } public Case getCase(int x, int y) { - return plateau[x/5][y/5].region[x%5][y%5]; + return getRegion(x,y).region[x%5][y%5]; } public Region getRegion(int x, int y ) { + /*if(x/5!=(x-1)/5) { + return plateau[x/5-1][y/5]; + } + else if(y/5!=(y-1)/5) { + return plateau[x/5][y/5-1]; + }*/ return plateau[x/5][y/5]; } public Region[][] getPlateau() { diff --git a/src/units/Unite.java b/src/units/Unite.java index 5303c5c3fb742feb344015febed73c75c352f2de..a40d44dc3c3b4ade2cc588d5da077f5ccc83b085 100644 --- a/src/units/Unite.java +++ b/src/units/Unite.java @@ -117,8 +117,11 @@ public abstract class Unite { } public boolean updatePosition(int x,int y) { - if(x>=0 && x<(plateau.getPlateau().length*plateau.getRegion(0, 0).region.length-1) && y>=0 && y<(plateau.getPlateau().length*plateau.getRegion(0, 0).region.length-1) ) { - if(this.plateau.getCase(x, y).getType() != Type.MOUNTAIN) { + if (x==33 || x==1 || y==29 || y==33 || y==0) { + return false; + } + if(x>=0 && x<((plateau.getPlateau().length*plateau.getRegion(0, 0).region.length)-1) && y>=0 && y<(plateau.getPlateau().length*plateau.getRegion(0, 0).region.length)-1 ) { + if(this.plateau.getCase(x, y).getType() != Type.MOUNTAIN ) { temp2 = temp; temp = this.plateau.getCase(x, y).getType(); this.plateau.getCase(x, y).setUnite(this); @@ -147,9 +150,9 @@ public abstract class Unite { public boolean move(char c) { if(c == 's') { - /*if (plateau.getCase(x+1,y).getUnite() != null || plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { - //combat(); - }*/ + if (plateau.getCase(x+1,y).getUnite() != null && plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { + return false; + } if (updatePosition(x+1,y)) { this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setType(temp2); @@ -160,6 +163,9 @@ public abstract class Unite { } } else if(c == 'd') { + if (plateau.getCase(x+1,y).getUnite() != null && plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { + return false; + } if (updatePosition(x,y+1)) { this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setType(temp2); @@ -170,6 +176,9 @@ public abstract class Unite { } } else if(c == 'q') { + if (plateau.getCase(x+1,y).getUnite() != null && plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { + return false; + } if (updatePosition(x,y-1)) { this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setType(temp2); @@ -180,6 +189,9 @@ public abstract class Unite { } } else if(c == 'z') { + if (plateau.getCase(x+1,y).getUnite() != null && plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { + return false; + } if (updatePosition(x-1, y)) { this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setType(temp2);