forked from menault/TD3_DEV51_Qualite_Algo
35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class HangmanPanel extends JPanel {
|
|
|
|
private int errors = 0;
|
|
|
|
/* Met à jour le nombre d'erreurs et redessine */
|
|
public void setErrors(int errors) {
|
|
this.errors = errors;
|
|
repaint();
|
|
}
|
|
|
|
/* Dessine le pendu en fonction des erreurs */
|
|
protected void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
|
|
// Structure du pendu
|
|
g.drawLine(50, 300, 200, 300);
|
|
g.drawLine(125, 300, 125, 50);
|
|
g.drawLine(125, 50, 250, 50);
|
|
g.drawLine(250, 50, 250, 80);
|
|
|
|
if (errors > 0) g.drawOval(230, 80, 40, 40); // tête
|
|
if (errors > 1) g.drawLine(250, 120, 250, 200); // corps
|
|
if (errors > 2) g.drawLine(250, 140, 220, 170); // bras gauche
|
|
if (errors > 3) g.drawLine(250, 140, 280, 170); // bras droit
|
|
if (errors > 4) g.drawLine(250, 200, 220, 250); // jambe gauche
|
|
if (errors > 5) g.drawLine(250, 200, 280, 250); // jambe droite
|
|
if (errors > 6) g.drawLine(230, 90, 270, 90); // yeux barres
|
|
if (errors > 7) g.drawString("X", 240, 100); // oeil gauche
|
|
if (errors > 8) g.drawString("X", 255, 100); // oeil droit
|
|
}
|
|
}
|