Skip to content
Snippets Groups Projects
Commit c62a0b38 authored by Paul RIPAULT's avatar Paul RIPAULT
Browse files

Merge branch 'master' into Paul

parents 573040c1 3303186d
Branches main
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ public class Crown extends Items{ ...@@ -14,7 +14,7 @@ public class Crown extends Items{
@Override @Override
public void usage(Joueur joueur) { public void usage(Joueur joueur) {
//TODO: premire version, tu prend la couronne tu gagne, ensuite faire de systme de rcup 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); joueur.setWin(true);
} }
......
...@@ -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("F"); 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 "? ";}
}
} }
package main;
public enum Direction {
HAUT, GAUCHE, BAS, DROITE;
}
package main; package main;
import java.util.Scanner;
import units.Paysant; import units.Paysant;
public class Main { public class Main {
private static Joueur winner; private static Joueur winner = new Joueur("Winner");
private int actionPoint; private int actionPoint;
public static void main(String[] args) { public static void main(String[] args) {
...@@ -16,21 +18,31 @@ public class Main { ...@@ -16,21 +18,31 @@ public class Main {
Plateau plateau = new Plateau(); Plateau plateau = new Plateau();
int x = 11; int x = 11;
int y = 0; int y = 10;
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); winner.getArmee().get(0).move(deplacement());
System.out.println('\n'); System.out.println('\n');
Affichage.affichage(plateau); Affichage.affichage(plateau);
Menu(); Menu();
plateau.getCase(12, 0);
Affichage.affichage(plateau);
} }
public static void Menu () { public static void Menu () {
System.out.print("Bienvenu dans Game of Crown, vous êtes actuellement sur le Menu !"); System.out.print("Bienvenue dans Game of Crown, vous êtes actuellement sur le Menu !");
Interface.start(); }
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; boolean gameEnd = false;
while(gameEnd){ while(gameEnd){
for (Joueur currentPlayer : joueurs) { for (Joueur currentPlayer : joueurs) {
......
...@@ -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;
} }
......
...@@ -9,10 +9,10 @@ public class Archer extends Unite{ ...@@ -9,10 +9,10 @@ public class Archer extends Unite{
public static final int ARMOR = 5; public static final int ARMOR = 5;
public static final int DAMAGE = 5; public static final int DAMAGE = 5;
public static final char SYMBOL = 'A'; public static final char SYMBOL = 'A';
public static final int VISION = 2;
public Archer(int x, int y, Plateau plateau, Joueur joueur) { 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 @Override
...@@ -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;
} }
} }
...@@ -9,9 +9,10 @@ public class Chevalier extends Unite { ...@@ -9,9 +9,10 @@ public class Chevalier extends Unite {
public static final int ARMOR = 10; public static final int ARMOR = 10;
public static final int DAMAGE = 5; public static final int DAMAGE = 5;
public static final char SYMBOL = 'C'; public static final char SYMBOL = 'C';
public static final int VISION = 2;
public Chevalier(int x, int y, Plateau plateau, Joueur joueur) { 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);
} }
......
...@@ -9,9 +9,10 @@ public class Eclaireur extends Unite { ...@@ -9,9 +9,10 @@ public class Eclaireur extends Unite {
public static final int ARMOR = 1; public static final int ARMOR = 1;
public static final int DAMAGE = 0; public static final int DAMAGE = 0;
public static final char SYMBOL = 'E'; public static final char SYMBOL = 'E';
public static final int VISION = 2;
public Eclaireur(int x, int y, Plateau plateau, Joueur joueur) { 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);
} }
......
...@@ -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);
} }
...@@ -49,7 +50,7 @@ public class Paysant extends Unite{ ...@@ -49,7 +50,7 @@ public class Paysant extends Unite{
sc.close(); sc.close();
return true; return true;
}else { }else {
//TODO:utiliser un systme de vrification d'entre globale //TODO:utiliser un système de vérification d'entrée globale
System.out.println("ERROR"); System.out.println("ERROR");
} }
...@@ -59,7 +60,7 @@ public class Paysant extends Unite{ ...@@ -59,7 +60,7 @@ public class Paysant extends Unite{
} }
public void combattre() { public void combattre() {
//TODO: il faut d'abord regarder si une unit est prsente autour //TODO: il faut d'abord regarder si une unité est présente autour
} }
public void actionGivePA() { public void actionGivePA() {
......
package units; package units;
import java.util.Random;
import items.Items; import items.Items;
import main.Affichage;
import main.Case; import main.Case;
import main.Direction;
import main.Event; import main.Event;
import main.Joueur; import main.Joueur;
import main.Plateau; import main.Plateau;
...@@ -16,11 +18,12 @@ public abstract class Unite { ...@@ -16,11 +18,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;
...@@ -30,7 +33,9 @@ public abstract class Unite { ...@@ -30,7 +33,9 @@ public abstract class Unite {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.joueur = joueur; this.joueur = joueur;
this.joueur.ajoutUnit(this);
this.item = null; this.item = null;
this.vision = vision;
} }
public int getId() { public int getId() {
...@@ -113,46 +118,112 @@ public abstract class Unite { ...@@ -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 ) { 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));
} }
return true; return true;
} }
return false; return false;
} }
//à voir le type //à voir le type
public boolean move(Direction d) { public boolean move(char c) {
if(d == Direction.BAS) { /*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)) { if (updatePosition(x+1,y)) {
this.plateau.getCase(x, y).setUnite(null); 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 true;
} }
} }
else if(d == Direction.DROITE) { else if(c == 'd') {
if (updatePosition(x,y+1)) { if (updatePosition(x,y+1)) {
this.plateau.getCase(x, y).setUnite(null); 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; return true;
} }
} }
else if(d == Direction.GAUCHE) { else if(c == 'q') {
if (updatePosition(x,y-1)) { if (updatePosition(x,y-1)) {
this.plateau.getCase(x, y).setUnite(null); 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; return true;
} }
} }
else if(d == Direction.HAUT) { else if(c == 'z') {
if (updatePosition(x-1, y)) { if (updatePosition(x-1, y)) {
this.plateau.getCase(x, y).setUnite(null); 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 true;
} }
} }
return false; 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 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 to comment