9 Commits

10 changed files with 245 additions and 23 deletions

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="TD3_DEV51_Qualite_Algo" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

6
TD3_DEV51_Qualite_Algo/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -0,0 +1,46 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
;
public class Game {
private Word word;
private int errors;
private final int maxErrors = 6;
public Game(Word word) {
this.word = word;
this.errors = 0;
}
/* Verify error number */
public int getErrors() {
return this.errors;
}
/* Put error max */
public int getMaxErrors() {
return this.maxErrors;
}
/* Vue call method VerifyLetter, check status letter false/True */
public boolean playLetter(char c) {
boolean correct = word.VerifyLetter(c);
if (!correct) {
errors++;
}
return correct;
}
/* All letter is completed : Won */
public boolean isWon() {
return word.IsComplete();
}
/* Lost if maxErrors is greater than or egal to errors */
public boolean isLost() {
return errors >= maxErrors;
}
}

View File

@@ -1,7 +1,49 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo; package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
public class Main { public class Main {
public static void main(String[] args) { 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

@@ -1,3 +1,5 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models;
public class Letter{ public class Letter{
private char letter; private char letter;
private boolean status = false; private boolean status = false;
@@ -6,11 +8,11 @@ public class Letter{
this.letter = letter; this.letter = letter;
} }
/* Show status */ /* Show status */
private boolean getStatus(){ public boolean getStatus(){
return status return status;
} }
/* Verify status true, false */ /* Verify status true, false */
private boolean isGood(char c){ public boolean isGood(char c){
if( this.letter == c){ if( this.letter == c){
this.status = true; this.status = true;
return true; return true;

View File

@@ -1,20 +1,22 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models;
import java.util.*; import java.util.*;
public class Word { public class Word {
private String word; private final String word;
private Letter[] tabLetter; private Letter[] tabLetter;
private String c; private String c;
private Word(String word){ private 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] = Letter(this.word.charAt(i)) this.tabLetter[i] = new Letter(this.word.charAt(i));
} }
} }
/* Lettre dans le mot */ /* Lettre dans le mot */
private boolean VerifyLetter(String c){ public boolean VerifyLetter(char c){
boolean return_bool = false; boolean return_bool = false;
for(Letter letter in this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
if(letter.isGood(c)){ if(letter.isGood(c)){
return_bool = true; return_bool = true;
@@ -25,8 +27,8 @@ public class Word {
} }
/* Le mot a été deviné */ /* Le mot a été deviné */
private boolean IsComplet(){ public boolean IsComplete(){
if(Letter letter : this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
return false; return false;
} }
@@ -34,16 +36,4 @@ public class Word {
} }
return true; return true;
} }
} }

View File

@@ -0,0 +1,96 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.View;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
public class hangedManView extends JComponent {
private int state;
private String word;
private String wrongLetters;
public hangedManView() throws IOException {
super();
this.state = 8;
this.word = "E _ E _ _ L E";
this.wrongLetters = "G H J Z R";
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int x = this.getWidth()/2;
int y = this.getHeight()/2;
if(this.state > 8) {
// paint une image
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{
// on paint un homme batton
// Base
if (this.state > 0) {
g2d.drawLine(x - 100, y + 100, x + 100, y + 100);
}
// Poteau vertical
if (this.state > 1) {
g2d.drawLine(x - 50, y + 100, x - 50, y - 100);
}
// Traverse horizontale
if (this.state > 2) {
g2d.drawLine(x - 50, y - 100, x + 50, y - 100);
}
// Petite corde verticale
if (this.state > 3) {
g2d.drawLine(x + 50, y - 100, x + 50, y - 70);
}
x += 50;
y -= 40;
// Tête
if (this.state > 4) {
g2d.drawOval(x - 15, y - 30, 30, 30);
}
// Corps
if (this.state > 5) {
g2d.drawLine(x, y, x, y + 40);
}
// Bras
if (this.state > 6) {
g2d.drawLine(x, y + 10, x - 20, y + 20);
g2d.drawLine(x, y + 10, x + 20, y + 20);
}
// Jambes
if (this.state > 7) {
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) {
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();
}
}