diff --git a/src/items/Crown.java b/src/items/Crown.java index 9aa883f6c422b1790205f6f6cbc49409065c1565..97da0c6ee93d6d1933b383591a117f2996e6a85a 100644 --- a/src/items/Crown.java +++ b/src/items/Crown.java @@ -14,7 +14,7 @@ public class Crown extends Items{ @Override public void usage(Joueur joueur) { - //TODO: premi�re version, tu prend la couronne tu gagne, ensuite faire de syst�me de r�cup et d'arriver au camp + //TODO: premi�re version, tu prend la couronne tu gagne, ensuite faire de syst�me de r�cup et d'arriver au camp joueur.setWin(true); } diff --git a/src/main/Affichage.java b/src/main/Affichage.java index 18e9ede5957a16be3e825c800ee650737c518e19..dcdcc1cee10c028de8c2c6ce60bf69d5e93cf3c6 100644 --- a/src/main/Affichage.java +++ b/src/main/Affichage.java @@ -3,24 +3,16 @@ package main; public class Affichage { public static void affichage(Plateau plateau){ - final char plaine = '.'; - final char montagne = '◼'; - final char inconnu = '~'; + for(int i=0; i< plateau.getPlateau().length*5; i++) { for(int j=0; j< plateau.getPlateau()[0].length*5; j++) { - if(plateau.getCase(i, j).getType()==Type.FORT) { - System.out.print("F"); - }else if(plateau.getCase(i, j).getUnite() != null) { - System.out.print(plateau.getCase(i, j).getUnite().getSymbol()); - }else { - if (plateau.getCase(i, j).getType()==Type.GRASS) { - System.out.print(plaine); - } - else if (plateau.getCase(i, j).getType()==Type.MOUNTAIN) { - System.out.print(montagne); + if(plateau.getCase(i, j).getUnite() != null) { + System.out.print(plateau.getCase(i, j).getUnite().getSymbol() + " "); + }else { + System.out.print(plateau.getCase(i, j).toString()); } - } } + System.out.println(); } } diff --git a/src/main/Case.java b/src/main/Case.java index 4341c4a07e8cd4af775ea441e5cb98402628d6bc..a47af92925524e6e3d8e5dc8a33a2cb2ca0cc3bb 100644 --- a/src/main/Case.java +++ b/src/main/Case.java @@ -7,12 +7,28 @@ public class Case { private boolean decouverte; private Event event; private Unite unite; + private int x; + private int y; public Case(Type type) { this.type = type; this.decouverte = false; this.event = null; this.unite = null; + this.x = 0; + this.y = 0; + } + public void setX(int x) { + this.x = x; + } + public void setY(int y) { + this.y = y; + } + public int getX() { + return this.x; + } + public int getY() { + return this.y; } public Type getType() { return type; @@ -45,4 +61,19 @@ public class Case { public void setType(Type type) { this.type = type; } + public String toString() { + if (!this.isDecouverte()) { + return "~ "; + } + else if (this.type == Type.GRASS) { + return ". "; + } + else if (this.type == Type.MOUNTAIN) { + return "Ѧ "; + } + else if (this.type == Type.FORT) { + return "♜ "; + } + else { return "? ";} + } } diff --git a/src/main/Direction.java b/src/main/Direction.java deleted file mode 100644 index 2ac77660afd332a7dcf93c7aca97bd07b57c7348..0000000000000000000000000000000000000000 --- a/src/main/Direction.java +++ /dev/null @@ -1,7 +0,0 @@ -package main; - -public enum Direction { -HAUT, GAUCHE, BAS, DROITE; -} - - diff --git a/src/main/Main.java b/src/main/Main.java index 6461b20e3f97c28201bc956e74d6bc85327aad17..8c43cd4b81b8f77432322b50d24bf95c989a9a06 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,9 +1,11 @@ package main; +import java.util.Scanner; + import units.Paysant; public class Main { - private static Joueur winner; + private static Joueur winner = new Joueur("Winner"); private int actionPoint; public static void main(String[] args) { @@ -16,21 +18,31 @@ public class Main { Plateau plateau = new Plateau(); int x = 11; - int y = 0; + int y = 10; plateau.getCase(x, y).setUnite(new Paysant(x, y, plateau, winner)); Affichage.affichage(plateau); - plateau.getCase(x, y).getUnite().move(Direction.HAUT); + winner.getArmee().get(0).move(deplacement()); System.out.println('\n'); Affichage.affichage(plateau); Menu(); + plateau.getCase(12, 0); + Affichage.affichage(plateau); } public static void Menu () { - System.out.print("Bienvenu dans Game of Crown, vous êtes actuellement sur le Menu !"); - Interface.start(); + System.out.print("Bienvenue dans Game of Crown, vous êtes actuellement sur le Menu !"); + } + public static char deplacement() { + Scanner sc = new Scanner(System.in); + System.out.println("Veuillez choisir une direction"); + while (!sc.hasNext("[zqsd]")) { + System.out.println("Cette touche n'est pas acceptés, veuillez réessayer"); + sc.next(); + } + return sc.next().charAt(0); } - public Joueur Game (Joueur[] joueurs) { + private Joueur Game (Joueur[] joueurs) { boolean gameEnd = false; while(gameEnd){ for (Joueur currentPlayer : joueurs) { diff --git a/src/main/Plateau.java b/src/main/Plateau.java index 661c721167313f47bf79f604cd3b800849e1997d..96d7a56ce0191f9e906f723db9d67ab676febe31 100644 --- a/src/main/Plateau.java +++ b/src/main/Plateau.java @@ -8,6 +8,9 @@ public class Plateau { for (int i = 0; i < plateau.length; i++) { for (int j = 0; j < plateau[0].length; j++) { plateau[i][j] = new Region(); + plateau[i][j].setX(i); + plateau[i][j].setY(j); + plateau[i][j].fillRegion(); } } } @@ -20,5 +23,10 @@ public class Plateau { public Region[][] getPlateau() { return plateau; } - + public int getLength() { + return plateau.length * plateau[0][0].region.length; + } + public int getWidth() { + return plateau[0].length * plateau[0][0].region.length; + } } diff --git a/src/main/Region.java b/src/main/Region.java index ca7d7dd413b428cf82caabfd95ce775dbd426892..4b9c87b60a9a005b45127bce1da81ddd540dc8ca 100644 --- a/src/main/Region.java +++ b/src/main/Region.java @@ -5,8 +5,13 @@ import java.util.Random; public class Region { public Case[][] region = new Case[5][5]; private Joueur proprietaire = null; + private int x; + private int y; public Region() { + + } + public void fillRegion() { Random random = new Random(); for (int i = 0; i < region.length; i++) { for (int j = 0; j < region[0].length; j++) { @@ -16,6 +21,8 @@ public class Region { else { region[i][j] = new Case(Type.GRASS); } + region[i][j].setX(i * x); + region[i][j].setY(j * y); } } int rd1 = (int)random.nextInt(5); @@ -23,6 +30,19 @@ public class Region { region[rd1][rd2].setEvent(Event.FORT); region[rd1][rd2].setType(Type.FORT); } + public void setX(int x) { + this.x = x; + } + public void setY(int y) { + this.y = y; + } + public int getX() { + return this.x; + } + public int getY() { + return this.y; + } + public void setProprietaire(Joueur proprietaire) { this.proprietaire = proprietaire; } diff --git a/src/units/Archer.java b/src/units/Archer.java index e526f2aff9325eab3e9456bce905122e099154c3..5cc6874b6fc0f4d5f6add23a75b0054025a9e30e 100644 --- a/src/units/Archer.java +++ b/src/units/Archer.java @@ -9,10 +9,10 @@ public class Archer extends Unite{ public static final int ARMOR = 5; public static final int DAMAGE = 5; public static final char SYMBOL = 'A'; + public static final int VISION = 2; public Archer(int x, int y, Plateau plateau, Joueur joueur) { - super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur); - + super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur, VISION); } @Override @@ -25,5 +25,4 @@ public class Archer extends Unite{ // TODO Auto-generated method stub return false; } - } diff --git a/src/units/Chevalier.java b/src/units/Chevalier.java index 6a1f134b0e0159438a440ea0dfae8efb83e8a802..1e263986754b56581a9bfef0245c32e05d449250 100644 --- a/src/units/Chevalier.java +++ b/src/units/Chevalier.java @@ -9,9 +9,10 @@ public class Chevalier extends Unite { public static final int ARMOR = 10; public static final int DAMAGE = 5; public static final char SYMBOL = 'C'; + public static final int VISION = 2; public Chevalier(int x, int y, Plateau plateau, Joueur joueur) { - super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur); + super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur, VISION); } diff --git a/src/units/Eclaireur.java b/src/units/Eclaireur.java index c7cbeba173c9f1807d4e641e7d2e3e17b1a666d4..4c02d3e172c8868dd8094b2b7c79a8580cc8b90b 100644 --- a/src/units/Eclaireur.java +++ b/src/units/Eclaireur.java @@ -9,9 +9,10 @@ public class Eclaireur extends Unite { public static final int ARMOR = 1; public static final int DAMAGE = 0; public static final char SYMBOL = 'E'; + public static final int VISION = 2; public Eclaireur(int x, int y, Plateau plateau, Joueur joueur) { - super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur); + super(x,y, plateau, SYMBOL, ARMOR, DAMAGE, joueur, VISION); } diff --git a/src/units/Paysant.java b/src/units/Paysant.java index aac3e29e5324a77b59b97c568441f0cffcb9c7a9..518bb00745c07e573ce109b0228b53109237ed60 100644 --- a/src/units/Paysant.java +++ b/src/units/Paysant.java @@ -12,9 +12,10 @@ public class Paysant extends Unite{ public static final int DAMAGE = 1; public static final char SYMBOL = 'p'; public static final int PATOGIVE = 1; + public static final int VISION = 2; public Paysant(int x, int y, Plateau plateau, Joueur joueur) { - super(x, y, plateau, SYMBOL, ARMOR, DAMAGE, joueur); + super(x, y, plateau, SYMBOL, ARMOR, DAMAGE, joueur, VISION); } @@ -49,7 +50,7 @@ public class Paysant extends Unite{ sc.close(); return true; }else { - //TODO:utiliser un syst�me de v�rification d'entr�e globale + //TODO:utiliser un système de vérification d'entrée globale System.out.println("ERROR"); } @@ -59,7 +60,7 @@ public class Paysant extends Unite{ } public void combattre() { - //TODO: il faut d'abord regarder si une unit� est pr�sente autour + //TODO: il faut d'abord regarder si une unité est présente autour } public void actionGivePA() { diff --git a/src/units/Unite.java b/src/units/Unite.java index 3bf47e916aa3575bac14c07fcbf9886678b44b8a..6892bb48ad8093010dfee65b929bbfeeed84eca1 100644 --- a/src/units/Unite.java +++ b/src/units/Unite.java @@ -1,8 +1,10 @@ package units; +import java.util.Random; + import items.Items; +import main.Affichage; import main.Case; -import main.Direction; import main.Event; import main.Joueur; import main.Plateau; @@ -16,11 +18,12 @@ public abstract class Unite { private int damage; private int x; private int y; + private int vision; public static int generalId = 1; private Joueur joueur; private Items item; - public Unite(int x, int y, Plateau plateau, char symbol, int armor, int damage, Joueur joueur) { + public Unite(int x, int y, Plateau plateau, char symbol, int armor, int damage, Joueur joueur, int vision) { this.id = generalId; generalId++; this.plateau = plateau; @@ -30,7 +33,9 @@ public abstract class Unite { this.x = x; this.y = y; this.joueur = joueur; + this.joueur.ajoutUnit(this); this.item = null; + this.vision = vision; } public int getId() { @@ -113,46 +118,112 @@ public abstract class Unite { if(x>=0 && x<plateau.getPlateau().length*plateau.getRegion(0, 0).region.length && y>=0 && y<plateau.getPlateau().length*plateau.getRegion(0, 0).region.length ) { this.plateau.getCase(x, y).setUnite(this); this.plateau.getCase(x, y).setType(Type.UNITE); - if(this.plateau.getCase(x, y).isDecouverte()==false) { - this.plateau.getCase(x, y).setDecouverte(true); - } if(this.plateau.getCase(x, y).getEvent() == Event.FORT) { this.plateau.getRegion(x, y).setProprietaire(joueur); - //this.joueur.getRoyaume().add(this.plateau.getRegion(x, y)); + this.joueur.getRoyaume().add(this.plateau.getRegion(x, y)); } return true; } return false; } //à voir le type - public boolean move(Direction d) { - if(d == Direction.BAS) { + public boolean move(char c) { + /*if(c=='s' && updatePosition(x+1,y))*/ + + if(c == 's') { + if (plateau.getCase(x+1,y).getUnite() != null || plateau.getCase(x+1, y).getUnite().getJoueur() != this.joueur) { + //combat(); + } if (updatePosition(x+1,y)) { this.plateau.getCase(x, y).setUnite(null); + this.plateau.getCase(x, y).setType(Type.GRASS); + this.x+=1; + updateDecouverte(this.plateau.getCase(x+1, y), this.vision); return true; } } - else if(d == Direction.DROITE) { + else if(c == 'd') { if (updatePosition(x,y+1)) { this.plateau.getCase(x, y).setUnite(null); + this.plateau.getCase(x, y).setType(Type.GRASS); + this.y+=1; + updateDecouverte(this.plateau.getCase(x, y+1), this.vision); return true; } } - else if(d == Direction.GAUCHE) { + else if(c == 'q') { if (updatePosition(x,y-1)) { this.plateau.getCase(x, y).setUnite(null); + this.plateau.getCase(x, y).setType(Type.GRASS); + this.y-=1; + updateDecouverte(this.plateau.getCase(x, y-1), this.vision); return true; } } - else if(d == Direction.HAUT) { + else if(c == 'z') { if (updatePosition(x-1, y)) { this.plateau.getCase(x, y).setUnite(null); + this.plateau.getCase(x, y).setType(Type.GRASS); + this.x-=1; + updateDecouverte(this.plateau.getCase(x-1, y), this.vision); return true; } } return false; } + public void teleporte() { + Random alea = new Random(); + int longueur = plateau.getPlateau().length*plateau.getRegion(0, 0).region.length; + int rd1 = alea.nextInt(longueur); + int rd2 = alea.nextInt(longueur); + + while(plateau.getCase(rd1, rd2).getType()!=Type.GRASS) { + rd1 = alea.nextInt(longueur); + rd2 = alea.nextInt(longueur); + } + updatePosition(rd1,rd2); + this.plateau.getCase(x, y).setUnite(null); + this.plateau.getCase(x, y).setType(Type.GRASS); + this.x=rd1; + this.y=rd2; + } + public void updateDecouverte (Case emplacement, int vision) { + System.out.println("" + emplacement.getX() + ", " + emplacement.getY()); + if (emplacement.getX()+1 < this.plateau.getLength()) { + if(this.plateau.getCase(emplacement.getX()+1, emplacement.getY()).isDecouverte()==false) { + this.plateau.getCase(emplacement.getX()+1, emplacement.getY()).setDecouverte(true); + } + if (vision-- > -1) { + updateDecouverte(this.plateau.getCase(emplacement.getX()+1, emplacement.getY()), vision--); + } + } + if (emplacement.getY()-1 > -1) { + if(this.plateau.getCase(emplacement.getX(), emplacement.getY() -1).isDecouverte()==false) { + this.plateau.getCase(emplacement.getX(), emplacement.getY() -1).setDecouverte(true); + } + if (vision-- > -1) { + updateDecouverte(this.plateau.getCase(emplacement.getX(), emplacement.getY() -1), vision--); + } + } + if (emplacement.getY()+1 < plateau.getWidth()) { + if(this.plateau.getCase(emplacement.getX(), emplacement.getY() +1).isDecouverte()==false) { + this.plateau.getCase(emplacement.getX(), emplacement.getY() +1).setDecouverte(true); + } + if (vision-- > -1) { + updateDecouverte(this.plateau.getCase(emplacement.getX(), emplacement.getY() +1), vision--); + } + } + if (emplacement.getX()-1 > -1) { + if(this.plateau.getCase(emplacement.getX()-1, emplacement.getY()).isDecouverte()==false) { + this.plateau.getCase(emplacement.getX()-1, emplacement.getY()).setDecouverte(true); + } + if (vision-- > -1) { + updateDecouverte(this.plateau.getCase(emplacement.getX()-1, emplacement.getY()), vision--); + } + } + } + public abstract String toString(); public abstract boolean action();