fin de la vue principal

This commit is contained in:
2025-10-08 14:45:55 +02:00
parent 111dcad559
commit 2f3a6df740
5 changed files with 78 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -1,6 +1,8 @@
package Controllers; package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
import Models.Word; import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
;
public class Game { public class Game {
private Word word; private Word word;

View File

@@ -1,7 +1,49 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo; package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
public class Main { import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
public static void main(String[] args) {
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setResizable(false);
frame.setLayout(new GridBagLayout());
GridBagConstraints GBC = new GridBagConstraints();
GBC.fill = GridBagConstraints.BOTH;
GBC.gridx = 0;
GBC.gridy = 0;
GBC.gridwidth = 1;
GBC.gridheight = 1;
GBC.weightx = 1;
GBC.weighty = 1;
hangedManView drawingView = new hangedManView();
frame.add(drawingView, GBC);
GBC.gridy = 1;
GBC.weighty = 0;
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
JTextField TextField = new JTextField();
TextField.setColumns(10);
panel.add(TextField,GBC);
JButton button = new JButton("send");
panel.add(button);
frame.add(panel,GBC);
frame.setVisible(true);
} }
} }

View File

@@ -14,7 +14,7 @@ public class Word {
} }
} }
/* Lettre dans le mot */ /* Lettre dans le mot */
private boolean VerifyLetter(char c){ public boolean VerifyLetter(char c){
boolean return_bool = false; boolean return_bool = false;
for(Letter letter : this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
@@ -27,7 +27,7 @@ public class Word {
} }
/* Le mot a été deviné */ /* Le mot a été deviné */
private boolean IsComplet(){ public boolean IsComplete(){
for(Letter letter : this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
return false; return false;
@@ -36,5 +36,4 @@ public class Word {
} }
return true; return true;
} }
} }

View File

@@ -1,31 +1,33 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.View; package fr.iutfbleau.TD3_DEV51_Qualite_Algo.View;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
public class hangedManView extends JComponent { public class hangedManView extends JComponent {
private int state; private int state;
private String word;
private String wrongLetters;
public hangedManView() throws IOException { public hangedManView() throws IOException {
super(); super();
this.state = 0; this.state = 8;
this.word = "E _ E _ _ L E";
this.wrongLetters = "G H J Z R";
} }
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
int x = 150; int x = this.getWidth()/2;
int y = 200; int y = this.getHeight()/2;
if(this.state > 8) { if(this.state > 8) {
// paint une image // paint une image
g2d.drawImage(new ImageIcon(Thread.currentThread().getContextClassLoader().getResource("resources/HangedGirl.jpg")).getImage(), x, y, this); 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);
}else{ }else{
// on paint un homme batton // on paint un homme batton
// Base // Base
@@ -67,9 +69,28 @@ public class hangedManView extends JComponent {
g2d.drawLine(x, y + 40, x + 20, y + 70); g2d.drawLine(x, y + 40, x + 20, y + 70);
} }
} }
// 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();
}
public void setWord(String word) {
this.word = word;
this.repaint();
}
public void setWrongLetters(String letters) {
this.wrongLetters = letters;
this.repaint();
} }
} }