Select Git revision
-
Francois .D authoredFrancois .D authored
Unite.java 5.44 KiB
package units;
import java.util.Random;
import items.Items;
import main.Case;
import main.Joueur;
import main.Plateau;
import main.Type;
public abstract class Unite {
private int id;
private Plateau plateau;
private char symbol;
private int armor;
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, int vision) {
this.id = generalId;
generalId++;
this.plateau = plateau;
this.symbol = symbol;
this.armor = armor;
this.damage = damage;
this.x = x;
this.y = y;
this.joueur = joueur;
this.joueur.ajoutUnit(this);
this.item = null;
this.vision = vision;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Plateau getPlateau() {
return plateau;
}
public char getSymbol() {
return symbol;
}
public void setSymbol(char symbol) {
this.symbol = symbol;
}
public int getArmor() {
return armor;
}
public void setArmor(int armor) {
this.armor = armor;
}
public int getDamage() {
return damage;
}
public Joueur getJoueur() {
return joueur;
}
public void setJoueur(Joueur joueur) {
this.joueur = joueur;
}
public void setDamage(int damage) {
this.damage = damage;
}
public Items getItem() {
return item;
}
public void setItem(Items item) {
this.item = item;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public static void resetNumbering() {
generalId = 0;
}
public boolean moove(Case unitCase) {
return false;
}
public boolean updatePosition(int x,int y) {
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);
return true;
}
return false;
}
//à voir le type
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(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(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(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();
}