projet-court-programmation-.../allumettes/Partie.java

49 lines
1 KiB
Java
Raw Permalink Normal View History

2023-06-20 19:05:21 +00:00
package allumettes;
public class Partie implements Jeu {
// Attributs
/** variable stockant le nombre d'allumettes encore en jeu */
private int nbAllumettes;
// Constructeurs
/** Constructeur par défaut de la classe Partie. */
public Partie() {
this.nbAllumettes = 13;
}
/**
* Constructeur de la classe Partie.
*
* @param nbAllumettes nombre d'allumettes initiales ( > 0 )
*/
public Partie(int nbAllumettes) {
if (nbAllumettes < 1) {
throw new ConfigurationException("Nombre d'allumettes initiales incorrectes ( < 1 )");
} else {
this.nbAllumettes = nbAllumettes;
}
}
// GETs
@Override
public int getNombreAllumettes() {
return this.nbAllumettes;
}
// Méthodes
@Override
public void retirer(int nbPrises) throws CoupInvalideException {
if (nbPrises < 1) {
throw new CoupInvalideException(nbPrises, "< 1");
} else {
this.nbAllumettes -= nbPrises;
}
}
}