Skip to content
Snippets Groups Projects
Commit cce7edc5 authored by Francois DEROUBAIX's avatar Francois DEROUBAIX
Browse files

Merge branch 'master' into Francois

parents d5af7154 663e9463
No related branches found
No related tags found
No related merge requests found
...@@ -3,24 +3,16 @@ package main; ...@@ -3,24 +3,16 @@ package main;
public class Affichage { public class Affichage {
public static void affichage(Plateau plateau){ 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 i=0; i< plateau.getPlateau().length*5; i++) {
for(int j=0; j< plateau.getPlateau()[0].length*5; j++) { for(int j=0; j< plateau.getPlateau()[0].length*5; j++) {
if(plateau.getCase(i, j).getType()==Type.FORT) { if(plateau.getCase(i, j).getUnite() != null) {
System.out.print("♜"); System.out.print(plateau.getCase(i, j).getUnite().getSymbol() + " ");
}else if(plateau.getCase(i, j).getUnite() != null) {
System.out.print(plateau.getCase(i, j).getUnite().getSymbol());
}else { }else {
if (plateau.getCase(i, j).getType()==Type.GRASS) { System.out.print(plateau.getCase(i, j).toString());
System.out.print(plaine);
}
else if (plateau.getCase(i, j).getType()==Type.MOUNTAIN) {
System.out.print(montagne);
}
} }
} }
System.out.println(); System.out.println();
} }
} }
......
...@@ -7,12 +7,28 @@ public class Case { ...@@ -7,12 +7,28 @@ public class Case {
private boolean decouverte; private boolean decouverte;
private Event event; private Event event;
private Unite unite; private Unite unite;
private int x;
private int y;
public Case(Type type) { public Case(Type type) {
this.type = type; this.type = type;
this.decouverte = false; this.decouverte = false;
this.event = null; this.event = null;
this.unite = 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() { public Type getType() {
return type; return type;
...@@ -45,4 +61,19 @@ public class Case { ...@@ -45,4 +61,19 @@ public class Case {
public void setType(Type type) { public void setType(Type type) {
this.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 "? ";}
}
} }
...@@ -15,15 +15,14 @@ public class Main { ...@@ -15,15 +15,14 @@ public class Main {
}*/ }*/
Plateau plateau = new Plateau(); Plateau plateau = new Plateau();
int x = 11; int x = 13;
int y = 0; int y = 23;
plateau.getCase(x, y).setUnite(new Paysant(x, y, plateau, winner)); plateau.getCase(x, y).setUnite(new Paysant(x, y, plateau, winner));
Affichage.affichage(plateau); Affichage.affichage(plateau);
plateau.getCase(x, y).getUnite().move(Direction.HAUT); plateau.getCase(x, y).getUnite().move(Direction.HAUT);
System.out.println('\n'); System.out.println('\n');
plateau.getCase(12, 0); plateau.getCase(12, 0);
Affichage.affichage(plateau); Affichage.affichage(plateau);
//Menu(); //Menu();
} }
......
...@@ -8,6 +8,9 @@ public class Plateau { ...@@ -8,6 +8,9 @@ public class Plateau {
for (int i = 0; i < plateau.length; i++) { for (int i = 0; i < plateau.length; i++) {
for (int j = 0; j < plateau[0].length; j++) { for (int j = 0; j < plateau[0].length; j++) {
plateau[i][j] = new Region(); 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 { ...@@ -20,5 +23,10 @@ public class Plateau {
public Region[][] getPlateau() { public Region[][] getPlateau() {
return plateau; 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; ...@@ -5,8 +5,13 @@ import java.util.Random;
public class Region { public class Region {
public Case[][] region = new Case[5][5]; public Case[][] region = new Case[5][5];
private Joueur proprietaire = null; private Joueur proprietaire = null;
private int x;
private int y;
public Region() { public Region() {
}
public void fillRegion() {
Random random = new Random(); Random random = new Random();
for (int i = 0; i < region.length; i++) { for (int i = 0; i < region.length; i++) {
for (int j = 0; j < region[0].length; j++) { for (int j = 0; j < region[0].length; j++) {
...@@ -16,6 +21,8 @@ public class Region { ...@@ -16,6 +21,8 @@ public class Region {
else { else {
region[i][j] = new Case(Type.GRASS); 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); int rd1 = (int)random.nextInt(5);
...@@ -23,6 +30,19 @@ public class Region { ...@@ -23,6 +30,19 @@ public class Region {
region[rd1][rd2].setEvent(Event.FORT); region[rd1][rd2].setEvent(Event.FORT);
region[rd1][rd2].setType(Type.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) { public void setProprietaire(Joueur proprietaire) {
this.proprietaire = proprietaire; this.proprietaire = proprietaire;
} }
......
...@@ -25,5 +25,4 @@ public class Archer extends Unite{ ...@@ -25,5 +25,4 @@ public class Archer extends Unite{
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
} }
...@@ -12,9 +12,10 @@ public class Paysant extends Unite{ ...@@ -12,9 +12,10 @@ public class Paysant extends Unite{
public static final int DAMAGE = 1; public static final int DAMAGE = 1;
public static final char SYMBOL = 'p'; public static final char SYMBOL = 'p';
public static final int PATOGIVE = 1; public static final int PATOGIVE = 1;
public static final int VISION = 2;
public Paysant(int x, int y, Plateau plateau, Joueur joueur) { 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 { ...@@ -16,11 +16,12 @@ public abstract class Unite {
private int damage; private int damage;
private int x; private int x;
private int y; private int y;
private int vision;
public static int generalId = 1; public static int generalId = 1;
private Joueur joueur; private Joueur joueur;
private Items item; 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; this.id = generalId;
generalId++; generalId++;
this.plateau = plateau; this.plateau = plateau;
...@@ -31,6 +32,7 @@ public abstract class Unite { ...@@ -31,6 +32,7 @@ public abstract class Unite {
this.y = y; this.y = y;
this.joueur = joueur; this.joueur = joueur;
this.item = null; this.item = null;
this.vision = vision;
} }
public int getId() { public int getId() {
...@@ -113,9 +115,6 @@ public abstract class Unite { ...@@ -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 ) { 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).setUnite(this);
this.plateau.getCase(x, y).setType(Type.UNITE); 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) { if(this.plateau.getCase(x, y).getEvent() == Event.FORT) {
this.plateau.getRegion(x, y).setProprietaire(joueur); 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));
...@@ -129,30 +128,71 @@ public abstract class Unite { ...@@ -129,30 +128,71 @@ public abstract class Unite {
if(d == Direction.BAS) { if(d == Direction.BAS) {
if (updatePosition(x+1,y)) { if (updatePosition(x+1,y)) {
this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x+1, y), this.vision);
return true; return true;
} }
} }
else if(d == Direction.DROITE) { else if(d == Direction.DROITE) {
if (updatePosition(x,y+1)) { if (updatePosition(x,y+1)) {
this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x, y+1), this.vision);
return true; return true;
} }
} }
else if(d == Direction.GAUCHE) { else if(d == Direction.GAUCHE) {
if (updatePosition(x,y-1)) { if (updatePosition(x,y-1)) {
this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x, y-1), this.vision);
return true; return true;
} }
} }
else if(d == Direction.HAUT) { else if(d == Direction.HAUT) {
if (updatePosition(x-1, y)) { if (updatePosition(x-1, y)) {
this.plateau.getCase(x, y).setUnite(null); this.plateau.getCase(x, y).setUnite(null);
updateDecouverte(this.plateau.getCase(x-1, y), this.vision);
return true; return true;
} }
} }
return false; 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 String toString();
public abstract boolean action(); 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