Skip to content
Snippets Groups Projects
Commit cf10839d authored by CARION Baptiste's avatar CARION Baptiste
Browse files

Ajout du brouillard de guerre et vision buggué

parent c979be3b
No related branches found
No related tags found
No related merge requests found
......@@ -3,22 +3,12 @@ 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());
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);
}
System.out.print(plateau.getCase(i, j).toString());
}
}
System.out.println();
......
......@@ -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 "F ";
}
else { return "? ";}
}
}
......@@ -17,21 +17,19 @@ public class Main {
}*/
Plateau plateau = new Plateau();
int x = 11;
int y = 0;
int x = 13;
int y = 23;
plateau.getCase(x, y).setUnite(new Paysant(x, y, plateau, winner));
Affichage.affichage(plateau);
plateau.getCase(x, y).getUnite().move(Direction.HAUT);
System.out.println('\n');
Affichage.affichage(plateau);
<<<<<<< HEAD
=======
Menu();
}
public static void Menu () {
System.out.print("Bienvenu dans Game of Crown, vous êtes actuellement sur le Menu !");
>>>>>>> 6e6d8e1d075a8855972540815248afce1757f9e0
}
public Joueur Game (Joueur[] joueurs) {
......
......@@ -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;
}
}
......@@ -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;
}
......
......@@ -25,5 +25,4 @@ public class Archer extends Unite{
// TODO Auto-generated method stub
return false;
}
}
......@@ -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);
}
......
......@@ -16,11 +16,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;
......@@ -31,6 +32,7 @@ public abstract class Unite {
this.y = y;
this.joueur = joueur;
this.item = null;
this.vision = vision;
}
public int getId() {
......@@ -113,9 +115,6 @@ 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));
......@@ -129,30 +128,71 @@ public abstract class Unite {
if(d == Direction.BAS) {
if (updatePosition(x+1,y)) {
this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x+1, y), this.vision);
return true;
}
}
else if(d == Direction.DROITE) {
if (updatePosition(x,y+1)) {
this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x, y+1), this.vision);
return true;
}
}
else if(d == Direction.GAUCHE) {
if (updatePosition(x,y-1)) {
this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x, y-1), this.vision);
return true;
}
}
else if(d == Direction.HAUT) {
if (updatePosition(x-1, y)) {
this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x-1, y), this.vision);
return true;
}
}
return false;
}
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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment