package allumettes; public class Joueur { // Attributs /** Le nom du joueur */ private String nom; /** Stratégie adoptée par le joueur */ private Strategie strat; // Constructeurs /** * Construire un joueur à partir de son nom et du nom de sa stratégie. * * @param nom nom du joueur * @param strat stratégie à adopter */ public Joueur(String nom, Strategie strat) { if (nom == null) { throw new ConfigurationException("Un joueur n'a pas de nom"); } else if (strat == null) { throw new ConfigurationException(this.nom + " n'a pas de stratégie"); } else { this.nom = nom; this.strat = strat; } } // GETs public String getNom() { return this.nom; } // SETs public void setNom(String nom) throws ConfigurationException { if (nom == null) { throw new ConfigurationException(this.nom + "doit avoir un nouveau nom valide"); } else { this.nom = nom; } } public void setStrat(Strategie strat) throws ConfigurationException { if (strat == null) { throw new ConfigurationException(this.nom + "doit avoir une stratégie valide"); } else { this.strat = strat; } } // Méthodes /** * Obtenir le nombre d'allumettes que le joueur prends. * * @param game Le jeu auquel on prend des allumettes * @return le nombre d'allumettes que le joueur prends * @throws CoupInvalideException si le coup * @throws ConfigurationException si le jeu fournis est null */ public int getPrise(Jeu game) throws CoupInvalideException, ConfigurationException { if (game == null) { throw new ConfigurationException(this.nom + " ne trouve pas la partie"); } else { return this.strat.nbPrise(game, this.nom); } } }