Select Git revision
WarriorCard.java
WarriorCard.java 1.45 KiB
package tp02;
/**
* @author Alexandre
* @version 0.01
* @since java21
*/
public class WarriorCard {
private String name;
private int strength = 0;
private int agility = 0;
/**
* @param name
* @param strength
* @param agility
*/
WarriorCard(String name, int strength, int agility){
this.name = name;
this.strength = strength;
this.agility = agility;
}
/**
* @param obj Objet qui est vérifié
* @return true si égale
* Vérifie si l'objet est égale
*/
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(this.getClass() != obj.getClass()){
return false;
}
WarriorCard other = (WarriorCard) obj;
if (this.name == null) {
if (other.name != null){
return false;
}
} else if (!this.name.equals(other.name)){
return false;
}
return true;
}
/**
* @param other une autre carte
* @return différence de strength
*/
public int compareStrength(WarriorCard other){
return this.strength - other.strength;
}
public int compareAgility(WarriorCard other){
return this.agility - other.agility;
}
public String toString(){
return this.name + "[S=" + this.strength + ",A=" + this.agility + "]";
}
}