134 lines
3.8 KiB
Java
134 lines
3.8 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package metier;
|
|
|
|
import java.util.Objects;
|
|
import javax.swing.Icon;
|
|
import javax.swing.JOptionPane;
|
|
import static javax.swing.JOptionPane.WARNING_MESSAGE;
|
|
|
|
/**
|
|
*
|
|
* @author Dominique_2
|
|
*/
|
|
public class Voleur extends Personnage{
|
|
|
|
private String outil;
|
|
private String [] outils={"Pierre","Feuille","Ciseaux"};
|
|
|
|
public Voleur(String nom, String img, int energie, int dureeVie, String outil) {
|
|
super(nom, img, energie, dureeVie);
|
|
this.outil = outil;
|
|
//this.butin = butin;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
int hash = 7;
|
|
hash = super.hashCode() + (29 * hash + Objects.hashCode(this.outil));
|
|
return hash;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param obj
|
|
* @return
|
|
*/
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj == null) {
|
|
return false;
|
|
}
|
|
if (getClass() != obj.getClass()) {
|
|
return false;
|
|
}
|
|
final Voleur other = (Voleur) obj;
|
|
if (!Objects.equals(this.outil, other.outil)) {
|
|
return false;
|
|
}
|
|
if (!super.equals(obj)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return super.toString() + "\t Outil=" + outil + "\nButin=";
|
|
}
|
|
|
|
/**
|
|
* Get the value of outil
|
|
*
|
|
* @return the value of outil
|
|
*/
|
|
public String getOutil() {
|
|
return outil;
|
|
}
|
|
|
|
/**
|
|
* Set the value of outil
|
|
*
|
|
* @param outil new value of outil
|
|
*/
|
|
public void setOutil(String outil) {
|
|
this.outil = outil;
|
|
}
|
|
|
|
public String[] getOutils() {
|
|
return outils;
|
|
}
|
|
|
|
public void setOutils(String[] outils) {
|
|
this.outils = outils;
|
|
}
|
|
|
|
@Override
|
|
public String rencontrer(Personnage unPerso) {
|
|
String titre = this.getNom() + " rencontre " + unPerso.getNom();
|
|
String message = "Que choisis-tu, " + unPerso.getNom() + "?";
|
|
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
|
|
Icon img = new javax.swing.ImageIcon(getClass().getResource("/img/pierreFeuilleCiseaux.jpg"));
|
|
|
|
|
|
String resultat = "";
|
|
String choixJoueur;
|
|
String choixAdversaire;
|
|
|
|
do {
|
|
int choixUtilisateur = JOptionPane.showOptionDialog(
|
|
null, message, titre, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
|
null, outils, 0);
|
|
|
|
choixJoueur = outils[choixUtilisateur];
|
|
choixAdversaire = outils[Jeu.genererNbAleatoire(0,2)];
|
|
if (choixJoueur.equals(choixAdversaire)) {
|
|
resultat = "Égalité, recommencez !";
|
|
} else if (
|
|
(choixJoueur.equals("Pierre") && choixAdversaire.equals("Ciseaux")) ||
|
|
(choixJoueur.equals("Feuille") && choixAdversaire.equals("Pierre")) ||
|
|
(choixJoueur.equals("Ciseaux") && choixAdversaire.equals("Feuille"))
|
|
) {
|
|
resultat = "Vous avez gagné !";
|
|
} else {
|
|
resultat = "Vous avez perdu !";
|
|
}
|
|
JOptionPane.showMessageDialog(null, "Vous avez choisi : " + choixJoueur + "\n"
|
|
+ unPerso.getNom() + " a choisi : " + choixAdversaire,
|
|
titre, JOptionPane.INFORMATION_MESSAGE);
|
|
} while(choixJoueur.equals(choixAdversaire));
|
|
|
|
|
|
JOptionPane.showMessageDialog(null, resultat, titre, JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
return resultat;
|
|
}
|
|
|
|
}
|