forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
18 Commits
ccb68428a8
...
master
Author | SHA1 | Date | |
---|---|---|---|
9512df6c58 | |||
07c0e435be | |||
c87527973e | |||
5336077fc4 | |||
c70c2b73ad | |||
90cd0b42a0 | |||
d4d8249c8b | |||
7bc1bb498f | |||
94e7394494 | |||
843043740c | |||
2f3a6df740 | |||
111dcad559 | |||
dbeed240d1 | |||
d07d4a7adc | |||
bc4aa06445 | |||
d05f9594d8 | |||
e5f9fd7fa8 | |||
0dbd7751e1 |
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
52
.idea/workspace.xml
generated
Normal file
52
.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="8fb861b5-29c0-47e2-a838-348dc02d9dc0" name="Changes" comment="" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="ComposerSettings">
|
||||||
|
<execution />
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectColorInfo"><![CDATA[{
|
||||||
|
"associatedIndex": 0
|
||||||
|
}]]></component>
|
||||||
|
<component name="ProjectId" id="33mEzzBwtK7Ze4qzSZYMoaUAwYr" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
|
"git-widget-placeholder": "master",
|
||||||
|
"last_opened_file_path": "C:/Users/rapha/Documents/Depo/TD3_DEV51_Bridja_Creuzet_Hochlaf",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="SharedIndexes">
|
||||||
|
<attachedChunks>
|
||||||
|
<set>
|
||||||
|
<option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.26830.84" />
|
||||||
|
</set>
|
||||||
|
</attachedChunks>
|
||||||
|
</component>
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="8fb861b5-29c0-47e2-a838-348dc02d9dc0" name="Changes" comment="" />
|
||||||
|
<created>1759914117184</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1759914117184</updated>
|
||||||
|
<workItem from="1759914119706" duration="22000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
</project>
|
13
TD3_DEV51_Qualite_Algo/.idea/compiler.xml
generated
Normal file
13
TD3_DEV51_Qualite_Algo/.idea/compiler.xml
generated
Normal 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>
|
7
TD3_DEV51_Qualite_Algo/.idea/encodings.xml
generated
Normal file
7
TD3_DEV51_Qualite_Algo/.idea/encodings.xml
generated
Normal 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>
|
20
TD3_DEV51_Qualite_Algo/.idea/jarRepositories.xml
generated
Normal file
20
TD3_DEV51_Qualite_Algo/.idea/jarRepositories.xml
generated
Normal 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
6
TD3_DEV51_Qualite_Algo/.idea/vcs.xml
generated
Normal 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>
|
17
TD3_DEV51_Qualite_Algo/pom.xml
Normal file
17
TD3_DEV51_Qualite_Algo/pom.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>fr.iutfbleau.TD3_DEV51_Qualite_Algo</groupId>
|
||||||
|
<artifactId>TD3_DEV51_Qualite_Algo</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>23</maven.compiler.source>
|
||||||
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
BIN
TD3_DEV51_Qualite_Algo/resources/HangedGirl.jpg
Normal file
BIN
TD3_DEV51_Qualite_Algo/resources/HangedGirl.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
22735
TD3_DEV51_Qualite_Algo/resources/liste_francais.txt
Normal file
22735
TD3_DEV51_Qualite_Algo/resources/liste_francais.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,184 @@
|
|||||||
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.util.*;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Difficulty;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Game {
|
||||||
|
private Word word;
|
||||||
|
private hangedManView hangedManView;
|
||||||
|
|
||||||
|
private int errors;
|
||||||
|
private int maxErrors = 9;
|
||||||
|
private String wrongLetters;
|
||||||
|
private long startTime;
|
||||||
|
private long endTime;
|
||||||
|
private final int maxTime = 120000; // 2 minutes
|
||||||
|
private List<Word> allwords;
|
||||||
|
private Difficulty difficulty;
|
||||||
|
|
||||||
|
/* Hangmam Game */
|
||||||
|
// Constructor
|
||||||
|
public Game(hangedManView hangedManView, Difficulty difficulty) {
|
||||||
|
this.hangedManView = hangedManView;
|
||||||
|
this.errors = 0;
|
||||||
|
this.wrongLetters = "";
|
||||||
|
this.startTime = System.currentTimeMillis();
|
||||||
|
this.endTime = 0;
|
||||||
|
|
||||||
|
allwords = WordList.readWordsFromFile();
|
||||||
|
|
||||||
|
switch (difficulty) {
|
||||||
|
case EASY:
|
||||||
|
this.word = selectWord(allwords, 0 , 7 );
|
||||||
|
break;
|
||||||
|
case MEDIUM:
|
||||||
|
this.word = selectWord(allwords, 0, Integer.MAX_VALUE);
|
||||||
|
break;
|
||||||
|
case HARD:
|
||||||
|
this.allwords = selectTwoWords(allwords);
|
||||||
|
this.word = new Word(this.allwords.get(0).getText()+"- "+this.allwords.get(1).getText());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
hangedManView.setWord(word.getWord());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Selected Word with conditions */
|
||||||
|
private Word selectWord(List<Word> list, int min, int max) {
|
||||||
|
|
||||||
|
for(int i = 0; i< list.size();i++){
|
||||||
|
|
||||||
|
//génère un int aléatoire
|
||||||
|
Random randomiser = new Random();
|
||||||
|
randomiser.setSeed(System.currentTimeMillis()-i);
|
||||||
|
Word word = list.get(randomiser.nextInt(0, list.size()));
|
||||||
|
|
||||||
|
int length = word.getText().length();
|
||||||
|
if (length >= min && length <= max) {
|
||||||
|
// Supprime les caractères diacritiques (accents)
|
||||||
|
return new Word(Normalizer.normalize(word.getText(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list.getFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Selected word level Difficult */
|
||||||
|
private List<Word> selectTwoWords(List<Word> list) {
|
||||||
|
return list.subList(0, Math.min(2, list.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters - Errors
|
||||||
|
public int getErrors() {
|
||||||
|
return this.errors;
|
||||||
|
}
|
||||||
|
/* Put error max */
|
||||||
|
public int getMaxErrors() {
|
||||||
|
return this.maxErrors;
|
||||||
|
}
|
||||||
|
// Getters - Wrong Letters
|
||||||
|
public String getWrongLetters() {
|
||||||
|
return this.wrongLetters;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the game is lost
|
||||||
|
private boolean isLost() {
|
||||||
|
return errors >= maxErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the game is won
|
||||||
|
public boolean isWon() {
|
||||||
|
int score = calculateScore();
|
||||||
|
if (word.IsComplete() && score > 0) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Bravo, voici ton score : "+score+"\n et ton temps : "+this.calculateTime()+"s (⓿_⓿).","(⓿_⓿)", JOptionPane.WARNING_MESSAGE);
|
||||||
|
System.exit(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// From view, verify if the letter is correct & finish the game if necessary (lost or won)
|
||||||
|
public boolean playLetter(char caractere) {
|
||||||
|
boolean correct;
|
||||||
|
|
||||||
|
if(difficulty == Difficulty.HARD){
|
||||||
|
correct = this.allwords.get(0).VerifyLetter(caractere) || this.allwords.get(1).VerifyLetter(caractere);
|
||||||
|
} else{
|
||||||
|
correct = word.VerifyLetter(caractere);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!correct) {
|
||||||
|
errors++;
|
||||||
|
hangedManView.setState(errors);
|
||||||
|
|
||||||
|
wrongLetters += caractere + " ";
|
||||||
|
hangedManView.setWrongLetters(wrongLetters);
|
||||||
|
|
||||||
|
if (isLost()) {
|
||||||
|
finishedGame();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hangedManView.setWord(word.getWord());
|
||||||
|
if (word.IsComplete()) {
|
||||||
|
finishedGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hangedManView.setWord(word.getWord());
|
||||||
|
|
||||||
|
return correct;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finish the game
|
||||||
|
private boolean finishedGame() {
|
||||||
|
this.endTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (isLost()) {
|
||||||
|
JOptionPane.showMessageDialog(null, "T'a perdu, pauvre con (⓿_⓿).\n Le mot était : "+this.word.getText(),"(⓿_⓿)", JOptionPane.WARNING_MESSAGE);
|
||||||
|
System.exit(0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isWon = isWon();
|
||||||
|
return isWon;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For view, return the remaining time
|
||||||
|
public long getRemainingTime() {
|
||||||
|
long elapsed = (System.currentTimeMillis() - startTime) / 1000;
|
||||||
|
long remaining = (maxTime / 1000) - elapsed;
|
||||||
|
|
||||||
|
if (remaining < 0) {
|
||||||
|
remaining = 0;
|
||||||
|
finishedGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(remaining, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get elapsed time for calculateScore
|
||||||
|
private long calculateTime() {
|
||||||
|
long elapsedTime = (endTime - startTime) / 1000;
|
||||||
|
return elapsedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate Score
|
||||||
|
public int calculateScore() {
|
||||||
|
long time = calculateTime();
|
||||||
|
int baseScore = 1000;
|
||||||
|
|
||||||
|
int errorPenalty = errors * 50;
|
||||||
|
int timePenalty = (int) time * 2;
|
||||||
|
|
||||||
|
int score = baseScore - errorPenalty - timePenalty;
|
||||||
|
if (score < 0) {
|
||||||
|
score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Handler;
|
||||||
|
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Game;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
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) {
|
||||||
|
try {
|
||||||
|
// 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);
|
||||||
|
this.letterField.setText("");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
|
||||||
|
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WordList {
|
||||||
|
|
||||||
|
public WordList()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public static List<Word> readWordsFromFile() {
|
||||||
|
List<Word> words = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader("resources/liste_francais.txt"))) {
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
line = line.trim(); // Supprime les espaces inutiles
|
||||||
|
if (!line.isEmpty()) {
|
||||||
|
words.add(new Word(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Erreur lors de la lecture du fichier : " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,55 @@
|
|||||||
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
||||||
|
|
||||||
public class Main {
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Game;
|
||||||
public static void main(String[] args) {
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers.Handler.SendLetterHandler;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Difficulty;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
|
||||||
|
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
Game gameControler = new Game(drawingView, Difficulty.HARD);
|
||||||
|
|
||||||
|
JButton button = new JButton("send");
|
||||||
|
button.addActionListener(new SendLetterHandler(frame,gameControler,TextField));
|
||||||
|
panel.add(button);
|
||||||
|
|
||||||
|
frame.add(panel,GBC);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models;
|
||||||
|
|
||||||
|
public enum Difficulty {
|
||||||
|
EASY, MEDIUM, HARD
|
||||||
|
}
|
@@ -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,15 +8,24 @@ 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;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if(this.status){
|
||||||
|
return letter + "";
|
||||||
|
}else{
|
||||||
|
return "_ ";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,22 +1,24 @@
|
|||||||
|
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 ArrayList<Letter> tabLetter;
|
||||||
private String c;
|
|
||||||
|
|
||||||
private Word(String word){
|
public Word(String word){
|
||||||
this.word = word;
|
this.word = word;
|
||||||
|
this.tabLetter = new ArrayList<>();
|
||||||
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.add(new Letter(this.word.charAt(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Lettre dans le mot */
|
/* Lettre dans le mot */
|
||||||
private boolean VerifyLetter(String c){
|
public boolean VerifyLetter(char character){
|
||||||
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(character)){
|
||||||
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,15 @@ public class Word {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public String getWord() {
|
||||||
|
String return_word = "";
|
||||||
|
for(Letter letter : this.tabLetter){
|
||||||
|
return_word += letter.toString();
|
||||||
|
}
|
||||||
|
return return_word;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText(){
|
||||||
|
return this.word;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -0,0 +1,103 @@
|
|||||||
|
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 = 0;
|
||||||
|
this.word = "";
|
||||||
|
this.wrongLetters = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
this.drawStand(g2d, x, y);
|
||||||
|
// 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
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawBudy(Graphics g2d,int x, int y) {
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user