2025-11-25 16:02:23 -05:00
|
|
|
|
package fr.iut_fbleau.Avalam;
|
2025-10-16 11:56:58 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-25 16:02:23 -05:00
|
|
|
|
* Représente une tour dans le jeu Avalam.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Une tour possède :
|
|
|
|
|
|
* - la couleur de son sommet
|
|
|
|
|
|
* - sa hauteur (nombre de pions)
|
|
|
|
|
|
*/
|
2025-10-16 11:56:58 +02:00
|
|
|
|
public class Tower {
|
2025-11-25 16:02:23 -05:00
|
|
|
|
|
|
|
|
|
|
private Color color;
|
|
|
|
|
|
private int height;
|
|
|
|
|
|
|
|
|
|
|
|
/** Nouvelle tour de hauteur 1 */
|
|
|
|
|
|
public Tower(Color color) {
|
|
|
|
|
|
this.color = color;
|
|
|
|
|
|
this.height = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Tour avec couleur et hauteur existantes */
|
|
|
|
|
|
public Tower(Color color, int height) {
|
|
|
|
|
|
this.color = color;
|
|
|
|
|
|
this.height = height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Color getColor() {
|
|
|
|
|
|
return color;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
|
|
return height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Fusionne this (destination) avec src (source).
|
|
|
|
|
|
* La source monte sur la destination →
|
|
|
|
|
|
* - la couleur du sommet devient celle de src
|
|
|
|
|
|
* - la hauteur s’additionne
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void mergeTower(Tower src) {
|
|
|
|
|
|
this.color = src.color;
|
|
|
|
|
|
this.height = this.height + src.height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
return color + "(" + height + ")";
|
|
|
|
|
|
}
|
2025-10-16 11:56:58 +02:00
|
|
|
|
}
|