Compare commits
10 Commits
master
...
06daa4e478
| Author | SHA1 | Date | |
|---|---|---|---|
| 06daa4e478 | |||
| 35c9fcd873 | |||
| ba7e16dc64 | |||
| 721543075c | |||
| d7ace2c8be | |||
| 56009640f5 | |||
| 80264f552f | |||
| 258aab00f3 | |||
| 5e8e4a1183 | |||
| 1741908a9d |
1
Diagramme.mdj
Normal file
1
Diagramme.mdj
Normal file
File diff suppressed because one or more lines are too long
48
Makefile
Normal file
48
Makefile
Normal file
@@ -0,0 +1,48 @@
|
||||
# Projet Pendu : fichier Makefile
|
||||
# Compatibilité : Linux
|
||||
|
||||
# Règle par défaut
|
||||
all : Pendu
|
||||
|
||||
# Dossiers
|
||||
IN = src/
|
||||
OUT = bin/
|
||||
|
||||
# Mots-clés
|
||||
JC = javac
|
||||
JCFLAGS = -encoding UTF-8 -implicit:none -cp $(OUT) -d $(OUT)
|
||||
|
||||
CLASSFILES = Pendu.class \
|
||||
Partie.class \
|
||||
Fenetre.class \
|
||||
Dessin.class
|
||||
|
||||
# Dépendances
|
||||
$(OUT)Pendu.class : $(IN)Pendu.java $(OUT)Partie.class $(OUT)Fenetre.class
|
||||
$(JC) $(JCFLAGS) $<
|
||||
|
||||
$(OUT)Partie.class : $(IN)Partie.java
|
||||
$(JC) $(JCFLAGS) $<
|
||||
|
||||
$(OUT)Fenetre.class : $(IN)Fenetre.java $(OUT)Partie.class $(OUT)Dessin.class
|
||||
$(JC) $(JCFLAGS) $<
|
||||
|
||||
$(OUT)Dessin.class : $(IN)Dessin.java
|
||||
$(JC) $(JCFLAGS) $<
|
||||
|
||||
# Commandes
|
||||
Pendu : $(OUT)Pendu.class
|
||||
|
||||
jar : $(OUT)Pendu.class
|
||||
jar -cfe Pendu.jar Pendu -C $(OUT) .
|
||||
|
||||
clean :
|
||||
-rm -f $(OUT)*.class
|
||||
-rm -f Pendu.jar
|
||||
|
||||
help : #(à implémenter plus tard)
|
||||
|
||||
# Buts factices
|
||||
.PHONY : all clean #(pour les cibles qui sont des commandes)
|
||||
|
||||
# Bug : gestion des chemins dans jar ?
|
||||
23
Modèles/Modèle Class.txt
Normal file
23
Modèles/Modèle Class.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
/**
|
||||
* La classe <code>Class</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public class Class {
|
||||
//Attributs
|
||||
|
||||
//Constructeur
|
||||
public Class() {
|
||||
|
||||
}
|
||||
//Méthodes
|
||||
|
||||
//Affichage
|
||||
public String toString() {
|
||||
return "" ;
|
||||
}
|
||||
}
|
||||
23
Modèles/Modèle Event.txt
Normal file
23
Modèles/Modèle Event.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* La classe <code>Event</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public class Event implements ActionListener {
|
||||
// Attributs
|
||||
|
||||
// Constructeur de l'évennement
|
||||
public Event() {
|
||||
|
||||
}
|
||||
// Action de l'évennement
|
||||
public void actionPerformed(ActionEvent event){
|
||||
|
||||
}
|
||||
}
|
||||
14
Modèles/Modèle Interface.txt
Normal file
14
Modèles/Modèle Interface.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
/**
|
||||
* L'interface <code>Interface</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public interface Interface {
|
||||
//Méthodes
|
||||
public void Action() ;
|
||||
|
||||
}
|
||||
14
Modèles/Modèle Main.txt
Normal file
14
Modèles/Modèle Main.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
/**
|
||||
* La classe <code>Main</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
}
|
||||
94
src/Dessin.java
Normal file
94
src/Dessin.java
Normal file
@@ -0,0 +1,94 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* La classe <code>Dessin</code> gère uniquement le dessin du pendu
|
||||
*
|
||||
* @version 0.1
|
||||
* @author Adrien
|
||||
* Date : 08-10-2025
|
||||
* Licence :
|
||||
*/
|
||||
public class Dessin extends JPanel {
|
||||
|
||||
// --- Constructeur ---
|
||||
public Dessin() {
|
||||
// Taille préférée pour s'intégrer dans Fenetre
|
||||
setPreferredSize(new Dimension(600, 350));
|
||||
setBackground(new Color(245, 245, 245));
|
||||
}
|
||||
|
||||
// --- Dessin principal ---
|
||||
@Override
|
||||
protected void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
|
||||
// Anti-aliasing pour des traits plus doux
|
||||
Graphics2D graphics2D = (Graphics2D) graphics.create();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics2D.setStroke(new BasicStroke(3f));
|
||||
graphics2D.setColor(Color.DARK_GRAY);
|
||||
|
||||
// Repères et proportions
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int marginPixels = Math.min(width, height) / 12; // marge proportionnelle
|
||||
|
||||
// Potence : socle
|
||||
int baseYCoordinate = height - marginPixels;
|
||||
graphics2D.drawLine(marginPixels, baseYCoordinate, width / 2, baseYCoordinate);
|
||||
|
||||
// Montant vertical
|
||||
int postXCoordinate = marginPixels + (width / 12);
|
||||
graphics2D.drawLine(postXCoordinate, baseYCoordinate, postXCoordinate, marginPixels);
|
||||
|
||||
// Traverse horizontale
|
||||
int beamLength = width / 3;
|
||||
graphics2D.drawLine(postXCoordinate, marginPixels, postXCoordinate + beamLength, marginPixels);
|
||||
|
||||
// Renfort diagonal
|
||||
graphics2D.drawLine(postXCoordinate, marginPixels + height / 10,
|
||||
postXCoordinate + width / 12, marginPixels);
|
||||
|
||||
// Corde
|
||||
int ropeXCoordinate = postXCoordinate + beamLength;
|
||||
int ropeTopYCoordinate = marginPixels;
|
||||
int ropeBottomYCoordinate = marginPixels + height / 12;
|
||||
graphics2D.drawLine(ropeXCoordinate, ropeTopYCoordinate, ropeXCoordinate, ropeBottomYCoordinate);
|
||||
|
||||
// Personnage : tête
|
||||
int headRadiusPixels = Math.min(width, height) / 16;
|
||||
int headCenterX = ropeXCoordinate;
|
||||
int headCenterY = ropeBottomYCoordinate + headRadiusPixels;
|
||||
graphics2D.drawOval(headCenterX - headRadiusPixels, headCenterY - headRadiusPixels,
|
||||
headRadiusPixels * 2, headRadiusPixels * 2);
|
||||
|
||||
// Corps
|
||||
int bodyTopYCoordinate = headCenterY + headRadiusPixels;
|
||||
int bodyBottomYCoordinate = bodyTopYCoordinate + height / 6;
|
||||
graphics2D.drawLine(headCenterX, bodyTopYCoordinate, headCenterX, bodyBottomYCoordinate);
|
||||
|
||||
// Bras
|
||||
int armSpanPixels = width / 10;
|
||||
int shouldersYCoordinate = bodyTopYCoordinate + height / 24;
|
||||
graphics2D.drawLine(headCenterX, shouldersYCoordinate,
|
||||
headCenterX - armSpanPixels, shouldersYCoordinate + height / 20);
|
||||
graphics2D.drawLine(headCenterX, shouldersYCoordinate,
|
||||
headCenterX + armSpanPixels, shouldersYCoordinate + height / 20);
|
||||
|
||||
// Jambes
|
||||
int legSpanPixels = width / 12;
|
||||
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate,
|
||||
headCenterX - legSpanPixels, bodyBottomYCoordinate + height / 8);
|
||||
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate,
|
||||
headCenterX + legSpanPixels, bodyBottomYCoordinate + height / 8);
|
||||
|
||||
graphics2D.dispose();
|
||||
}
|
||||
|
||||
// Affichage
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
145
src/Fenetre.java
Normal file
145
src/Fenetre.java
Normal file
@@ -0,0 +1,145 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* La classe <code>Fenetre</code> gère uniquement l'interface graphique :
|
||||
* - zone de dessin (assurée par la classe Dessin)
|
||||
* - affichage du mot masqué
|
||||
* - saisie d'une lettre (événement remonté via un handler)
|
||||
*
|
||||
* Aucune logique de jeu (choix/vérification du mot) n'est ici.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Adrien
|
||||
* Date : 08-10-25
|
||||
* Licence :
|
||||
*/
|
||||
public class Fenetre {
|
||||
|
||||
// --- Composants de l'interface (UI only) ---
|
||||
private JFrame window;
|
||||
private JLabel wordLabel;
|
||||
private JTextField letterInput;
|
||||
private JButton sendButton;
|
||||
private JPanel drawZone; // instance de Dessin
|
||||
|
||||
// Handler externe pour la lettre soumise (fourni par la classe Partie / contrôleur)
|
||||
private Consumer<Character> onLetterSubmitted;
|
||||
|
||||
// --- Constructeur (orchestration courte) ---
|
||||
public Fenetre() {
|
||||
setupWindow();
|
||||
JPanel root = createRoot();
|
||||
window.setContentPane(root);
|
||||
|
||||
drawZone = createDrawZone(); // -> new Dessin()
|
||||
root.add(drawZone);
|
||||
|
||||
wordLabel = createWordLabel();
|
||||
root.add(wordLabel);
|
||||
|
||||
JPanel inputPanel = createInputPanel();
|
||||
root.add(inputPanel);
|
||||
|
||||
window.setVisible(true);
|
||||
letterInput.requestFocusInWindow();
|
||||
}
|
||||
|
||||
// --- Initialisation fenêtre ---
|
||||
/** Configure la fenêtre principale (titre, taille, fermeture). */
|
||||
private void setupWindow() {
|
||||
window = new JFrame("Jeu du Pendu");
|
||||
window.setSize(600, 600);
|
||||
window.setLocationRelativeTo(null);
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
/** Crée le conteneur principal vertical. */
|
||||
private JPanel createRoot() {
|
||||
JPanel root = new JPanel();
|
||||
root.setLayout(new BoxLayout(root, BoxLayout.Y_AXIS));
|
||||
return root;
|
||||
}
|
||||
|
||||
// --- Sous-composants UI ---
|
||||
/** Crée la zone de dessin via la classe Dessin. */
|
||||
private JPanel createDrawZone() {
|
||||
return new Dessin();
|
||||
}
|
||||
|
||||
/** Crée le label d'affichage du mot (placeholder jusqu'à injection par Partie). */
|
||||
private JLabel createWordLabel() {
|
||||
JLabel label = new JLabel("_ _ _ _ _", SwingConstants.CENTER);
|
||||
label.setFont(new Font("Segoe UI", Font.BOLD, 32));
|
||||
label.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10));
|
||||
label.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
return label;
|
||||
}
|
||||
|
||||
/** Crée la zone de saisie (champ + bouton) et branche l'action. */
|
||||
private JPanel createInputPanel() {
|
||||
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
|
||||
JLabel prompt = new JLabel("Entrez une lettre :");
|
||||
|
||||
letterInput = new JTextField(2);
|
||||
letterInput.setHorizontalAlignment(JTextField.CENTER);
|
||||
letterInput.setFont(new Font("Segoe UI", Font.BOLD, 24));
|
||||
|
||||
sendButton = new JButton("Envoyer");
|
||||
|
||||
Action sendAction = new AbstractAction() {
|
||||
@Override public void actionPerformed(ActionEvent e) { submitLetter(); }
|
||||
};
|
||||
sendButton.addActionListener(sendAction);
|
||||
letterInput.addActionListener(sendAction);
|
||||
|
||||
letterInput.addKeyListener(new KeyAdapter() {
|
||||
@Override public void keyTyped(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
if (!Character.isLetter(c) || letterInput.getText().length() >= 1) e.consume();
|
||||
else e.setKeyChar(Character.toUpperCase(c));
|
||||
}
|
||||
});
|
||||
|
||||
inputPanel.add(prompt);
|
||||
inputPanel.add(letterInput);
|
||||
inputPanel.add(sendButton);
|
||||
return inputPanel;
|
||||
}
|
||||
|
||||
// --- Partie <-> UI ---
|
||||
|
||||
/** Définit le texte du mot affiché (ex: "_ _ A _ _") fourni par la classe Partie. */
|
||||
public void setWordDisplay(String maskedWord) {
|
||||
wordLabel.setText(maskedWord != null ? maskedWord : "");
|
||||
}
|
||||
|
||||
/** Définit le handler appelé quand l'utilisateur soumet une lettre. */
|
||||
public void setOnLetterSubmitted(Consumer<Character> handler) {
|
||||
this.onLetterSubmitted = handler;
|
||||
}
|
||||
|
||||
// --- Méthodes privées UI ---
|
||||
/** Récupère la lettre et notifie le handler externe (aucune logique de jeu ici). */
|
||||
private void submitLetter() {
|
||||
String text = letterInput.getText().trim().toUpperCase();
|
||||
letterInput.setText("");
|
||||
if (text.length() != 1 || !text.matches("[A-Z]")) {
|
||||
JOptionPane.showMessageDialog(window, "Veuillez entrer une seule lettre (A-Z).");
|
||||
return;
|
||||
}
|
||||
if (onLetterSubmitted != null) onLetterSubmitted.accept(text.charAt(0));
|
||||
else JOptionPane.showMessageDialog(window, "Lettre soumise (placeholder) : " + text);
|
||||
}
|
||||
|
||||
// --- Méthode principale de test ---
|
||||
public static void main(String[] args) {
|
||||
Fenetre f = new Fenetre();
|
||||
f.setWordDisplay("_ _ _ _ _"); // placeholder
|
||||
f.setOnLetterSubmitted(ch ->
|
||||
JOptionPane.showMessageDialog(null, "Lettre reçue : " + ch + " (sans logique de jeu)")
|
||||
);
|
||||
}
|
||||
}
|
||||
23
src/Partie.java
Normal file
23
src/Partie.java
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
/**
|
||||
* La classe <code>Partie</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public class Partie {
|
||||
//Attributs
|
||||
|
||||
//Constructeur
|
||||
public Partie() {
|
||||
|
||||
}
|
||||
//Méthodes
|
||||
|
||||
//Affichage
|
||||
public String toString() {
|
||||
return "" ;
|
||||
}
|
||||
}
|
||||
14
src/Pendu.java
Normal file
14
src/Pendu.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
/**
|
||||
* La classe <code>Pendu</code>
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* Licence :
|
||||
*/
|
||||
public class Pendu {
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user