Event commentaire

This commit is contained in:
2025-10-08 15:15:04 +02:00
parent 90874a3296
commit 62f6f94be7
8 changed files with 25 additions and 32 deletions

BIN
src/Dessin.class Normal file

Binary file not shown.

View File

@@ -47,8 +47,7 @@ public class Dessin extends JPanel {
graphics2D.drawLine(postXCoordinate, marginPixels, postXCoordinate + beamLength, marginPixels); graphics2D.drawLine(postXCoordinate, marginPixels, postXCoordinate + beamLength, marginPixels);
// Renfort diagonal // Renfort diagonal
graphics2D.drawLine(postXCoordinate, marginPixels + height / 10, graphics2D.drawLine(postXCoordinate, marginPixels + height / 10, postXCoordinate + width / 12, marginPixels);
postXCoordinate + width / 12, marginPixels);
// Corde // Corde
int ropeXCoordinate = postXCoordinate + beamLength; int ropeXCoordinate = postXCoordinate + beamLength;
@@ -60,8 +59,7 @@ public class Dessin extends JPanel {
int headRadiusPixels = Math.min(width, height) / 16; int headRadiusPixels = Math.min(width, height) / 16;
int headCenterX = ropeXCoordinate; int headCenterX = ropeXCoordinate;
int headCenterY = ropeBottomYCoordinate + headRadiusPixels; int headCenterY = ropeBottomYCoordinate + headRadiusPixels;
graphics2D.drawOval(headCenterX - headRadiusPixels, headCenterY - headRadiusPixels, graphics2D.drawOval(headCenterX - headRadiusPixels, headCenterY - headRadiusPixels, headRadiusPixels * 2, headRadiusPixels * 2);
headRadiusPixels * 2, headRadiusPixels * 2);
// Corps // Corps
int bodyTopYCoordinate = headCenterY + headRadiusPixels; int bodyTopYCoordinate = headCenterY + headRadiusPixels;
@@ -71,17 +69,13 @@ public class Dessin extends JPanel {
// Bras // Bras
int armSpanPixels = width / 10; int armSpanPixels = width / 10;
int shouldersYCoordinate = bodyTopYCoordinate + height / 24; int shouldersYCoordinate = bodyTopYCoordinate + height / 24;
graphics2D.drawLine(headCenterX, shouldersYCoordinate, graphics2D.drawLine(headCenterX, shouldersYCoordinate, headCenterX - armSpanPixels, shouldersYCoordinate + height / 20);
headCenterX - armSpanPixels, shouldersYCoordinate + height / 20); graphics2D.drawLine(headCenterX, shouldersYCoordinate, headCenterX + armSpanPixels, shouldersYCoordinate + height / 20);
graphics2D.drawLine(headCenterX, shouldersYCoordinate,
headCenterX + armSpanPixels, shouldersYCoordinate + height / 20);
// Jambes // Jambes
int legSpanPixels = width / 12; int legSpanPixels = width / 12;
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate, graphics2D.drawLine(headCenterX, bodyBottomYCoordinate, headCenterX - legSpanPixels, bodyBottomYCoordinate + height / 8);
headCenterX - legSpanPixels, bodyBottomYCoordinate + height / 8); graphics2D.drawLine(headCenterX, bodyBottomYCoordinate, headCenterX + legSpanPixels, bodyBottomYCoordinate + height / 8);
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate,
headCenterX + legSpanPixels, bodyBottomYCoordinate + height / 8);
graphics2D.dispose(); graphics2D.dispose();
} }

BIN
src/Event$1.class Normal file

Binary file not shown.

BIN
src/Event.class Normal file

Binary file not shown.

View File

@@ -3,28 +3,28 @@ import java.awt.event.*;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
* La classe <code>Event</code> regroupe et branche tous les listeners liés à Fenetre. * La classe <code>Event</code> regroupe et branche tous les listeners liés à Fenetre.
* - Validation de la saisie (1 lettre A-Z, majuscule) * - Validation de la saisie (1 lettre A-Z, majuscule)
* - Action sur Entrée ou clic bouton * - Action sur Entrée ou clic bouton
* - Notification du handler externe (fourni au constructeur) * - Notification du handler externe (fourni au constructeur)
* Aucune logique de jeu ici. * Aucune logique de jeu ici.
* @version 1.2 * @version 1.3
* author Adrien * author Adrien
* Date : 08-10-2025 * Date : 08-10-2025
* Licence : */
*/
public class Event implements ActionListener { public class Event implements ActionListener {
private final Fenetre window; private final Fenetre window;
private final Consumer<Character> onLetterSubmitted; private final Consumer<Character> onLetterSubmitted;
/** Constructeur : conserve les références et branche les événements. */
public Event(Fenetre window, Consumer<Character> onLetterSubmitted) { public Event(Fenetre window, Consumer<Character> onLetterSubmitted) {
this.window = window; this.window = window;
this.onLetterSubmitted = onLetterSubmitted; this.onLetterSubmitted = onLetterSubmitted;
wireEvents(); wireEvents();
} }
/** Branche les listeners sur les composants de Fenetre. */ /** Branche les listeners sur les composants de Fenetre.*/
private void wireEvents() { private void wireEvents() {
JTextField letterInput = window.getLetterInput(); JTextField letterInput = window.getLetterInput();
JButton sendButton = window.getSendButton(); JButton sendButton = window.getSendButton();
@@ -47,27 +47,26 @@ public class Event implements ActionListener {
}); });
} }
/** Réagit à Entrée ou au clic bouton : soumet la lettre. */ /** Réagit à Entrée ou au clic bouton : récupère, valide et transmet la lettre. */
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
submitLetter();
}
/** Récupère, valide et transmet la lettre au handler externe. */
private void submitLetter() {
JTextField letterInput = window.getLetterInput(); JTextField letterInput = window.getLetterInput();
String inputText = letterInput.getText().trim().toUpperCase();
letterInput.setText("");
String inputText = letterInput.getText().trim().toUpperCase();
letterInput.setText(""); // reset du champ après tentative
// Validation : exactement une lettre AZ
if (inputText.length() != 1 || !inputText.matches("[A-Z]")) { if (inputText.length() != 1 || !inputText.matches("[A-Z]")) {
JOptionPane.showMessageDialog(window.getWindow(), "Veuillez entrer une seule lettre (A-Z)."); JOptionPane.showMessageDialog(window.getWindow(), "Veuillez entrer une seule lettre (A-Z).");
return; return;
} }
// Notification du handler externe, sinon placeholder
if (onLetterSubmitted != null) { if (onLetterSubmitted != null) {
onLetterSubmitted.accept(inputText.charAt(0)); onLetterSubmitted.accept(inputText.charAt(0));
} else { } else {
JOptionPane.showMessageDialog(window.getWindow(), "Lettre soumise (placeholder) : " + inputText); JOptionPane.showMessageDialog(window.getWindow(),
"Lettre soumise (placeholder) : " + inputText);
} }
} }
} }

BIN
src/Fenetre.class Normal file

Binary file not shown.

BIN
src/Partie.class Normal file

Binary file not shown.

BIN
src/Pendu.class Normal file

Binary file not shown.