forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
1 Commits
2f3a6df740
...
Hochlaf-Vu
Author | SHA1 | Date | |
---|---|---|---|
843043740c |
@@ -0,0 +1,31 @@
|
|||||||
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Handler;
|
||||||
|
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Game;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class SendLetterHandler implements ActionListener {
|
||||||
|
|
||||||
|
private JFrame frame;
|
||||||
|
private Game gameControler;
|
||||||
|
private JTextField letterField;
|
||||||
|
|
||||||
|
public SendLetterHandler(JFrame frame, Game gameControler, JTextField letterField) {
|
||||||
|
this.frame = frame;
|
||||||
|
this.gameControler = gameControler;
|
||||||
|
this.letterField = letterField;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// on récupère la lettre du champs de saisie
|
||||||
|
if(this.letterField.getText().length() > 1) {
|
||||||
|
JOptionPane.showMessageDialog(this.frame, "Veuillez n'envoyer qu'une seule lettre. Merci (⓿_⓿).","(⓿_⓿)", JOptionPane.WARNING_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char letter = letterField.getText().charAt(0);
|
||||||
|
this.gameControler.playLetter(letter);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,8 @@
|
|||||||
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
||||||
|
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Game;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Handler.SendLetterHandler;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
|
||||||
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -8,6 +11,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
// TODO
|
||||||
|
Game gameControler = new Game(new Word(""));
|
||||||
|
// TODO
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
@@ -28,7 +34,6 @@ public class Main {
|
|||||||
hangedManView drawingView = new hangedManView();
|
hangedManView drawingView = new hangedManView();
|
||||||
frame.add(drawingView, GBC);
|
frame.add(drawingView, GBC);
|
||||||
|
|
||||||
|
|
||||||
GBC.gridy = 1;
|
GBC.gridy = 1;
|
||||||
GBC.weighty = 0;
|
GBC.weighty = 0;
|
||||||
|
|
||||||
@@ -40,6 +45,7 @@ public class Main {
|
|||||||
panel.add(TextField,GBC);
|
panel.add(TextField,GBC);
|
||||||
|
|
||||||
JButton button = new JButton("send");
|
JButton button = new JButton("send");
|
||||||
|
button.addActionListener(new SendLetterHandler(frame,gameControler,TextField));
|
||||||
panel.add(button);
|
panel.add(button);
|
||||||
|
|
||||||
frame.add(panel,GBC);
|
frame.add(panel,GBC);
|
||||||
|
@@ -7,7 +7,7 @@ public class Word {
|
|||||||
private Letter[] tabLetter;
|
private Letter[] tabLetter;
|
||||||
private String c;
|
private String c;
|
||||||
|
|
||||||
private Word(String word){
|
public Word(String word){
|
||||||
this.word = word;
|
this.word = word;
|
||||||
for(int i = 0; i< this.word.length();i++){
|
for(int i = 0; i< this.word.length();i++){
|
||||||
this.tabLetter[i] = new Letter(this.word.charAt(i));
|
this.tabLetter[i] = new Letter(this.word.charAt(i));
|
||||||
|
@@ -13,8 +13,15 @@ public class hangedManView extends JComponent {
|
|||||||
public hangedManView() throws IOException {
|
public hangedManView() throws IOException {
|
||||||
super();
|
super();
|
||||||
this.state = 8;
|
this.state = 8;
|
||||||
this.word = "E _ E _ _ L E";
|
this.word = "";
|
||||||
this.wrongLetters = "G H J Z R";
|
this.wrongLetters = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public hangedManView(String word) throws IOException {
|
||||||
|
super();
|
||||||
|
this.state = 8;
|
||||||
|
this.word = word;
|
||||||
|
this.wrongLetters = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
@@ -29,7 +36,23 @@ public class hangedManView extends JComponent {
|
|||||||
double ratio = 0.5;
|
double ratio = 0.5;
|
||||||
g2d.drawImage(new ImageIcon("resources/HangedGirl.jpg").getImage(), (this.getWidth()-(int) (567*ratio))/2, 0, (int) (567*ratio), (int) (1080*ratio), this);
|
g2d.drawImage(new ImageIcon("resources/HangedGirl.jpg").getImage(), (this.getWidth()-(int) (567*ratio))/2, 0, (int) (567*ratio), (int) (1080*ratio), this);
|
||||||
}else{
|
}else{
|
||||||
|
this.drawStand(g2d, x, y);
|
||||||
// on paint un homme batton
|
// on paint un homme batton
|
||||||
|
x += 50;
|
||||||
|
y -= 40;
|
||||||
|
this.drawBudy(g2d, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// on dessine le mot en dessous du pendu et au centre de la fenêtre.
|
||||||
|
g2d.setFont(new Font("Roboto", Font.BOLD, 20));
|
||||||
|
g2d.drawString(this.word, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.word))/2, this.getHeight()-50);
|
||||||
|
|
||||||
|
// on dessine les mauvaises lettres en rouge
|
||||||
|
g2d.setColor(Color.RED);
|
||||||
|
g2d.drawString(this.wrongLetters, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.wrongLetters))/2, this.getHeight()-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawStand(Graphics2D g2d, int x, int y) {
|
||||||
// Base
|
// Base
|
||||||
if (this.state > 0) {
|
if (this.state > 0) {
|
||||||
g2d.drawLine(x - 100, y + 100, x + 100, y + 100);
|
g2d.drawLine(x - 100, y + 100, x + 100, y + 100);
|
||||||
@@ -46,9 +69,9 @@ public class hangedManView extends JComponent {
|
|||||||
if (this.state > 3) {
|
if (this.state > 3) {
|
||||||
g2d.drawLine(x + 50, y - 100, x + 50, y - 70);
|
g2d.drawLine(x + 50, y - 100, x + 50, y - 70);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x += 50;
|
private void drawBudy(Graphics g2d,int x, int y) {
|
||||||
y -= 40;
|
|
||||||
|
|
||||||
// Tête
|
// Tête
|
||||||
if (this.state > 4) {
|
if (this.state > 4) {
|
||||||
@@ -70,15 +93,6 @@ public class hangedManView extends JComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on dessine le mot en dessous du pendu et au centre de la fenêtre.
|
|
||||||
g2d.setFont(new Font("Roboto", Font.BOLD, 20));
|
|
||||||
g2d.drawString(this.word, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.word))/2, this.getHeight()-50);
|
|
||||||
|
|
||||||
// on dessine les mauvaises lettres en rouge
|
|
||||||
g2d.setColor(Color.RED);
|
|
||||||
g2d.drawString(this.wrongLetters, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.wrongLetters))/2, this.getHeight()-10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setState(int state) {
|
public void setState(int state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.repaint();
|
this.repaint();
|
||||||
|
Reference in New Issue
Block a user