This commit is contained in:
Rémi Heredero 2021-11-21 15:44:55 +01:00
parent cdc427d4be
commit c49a63f843
4 changed files with 19 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,16 @@
package lab6; package lab6;
import java.awt.Color;
import hevs.graphics.FunGraphics; import hevs.graphics.FunGraphics;
public class HangMan { public class HangMan {
final int MAX_STEPS = 8; final int MAX_STEPS = 8;
final int scale = 2; final int scale = 2;
int current_step = 0; int current_step = 0;
String inputLetter = "Inputed letter: ";
String inputLetter1 = "";
String inputLetter2 = "";
WordManager word = new WordManager(); WordManager word = new WordManager();
FunGraphics man = new FunGraphics(300 * scale, 300 * scale, 0, 0, "Hangman", true); FunGraphics man = new FunGraphics(300 * scale, 300 * scale, 0, 0, "Hangman", true);
@ -14,6 +19,15 @@ public class HangMan {
// System.out.print("Please enter a new letter: "); // System.out.print("Please enter a new letter: ");
// char c = Input.readChar(); // char c = Input.readChar();
char c = Dialogs.getChar("Please enter a new letter"); char c = Dialogs.getChar("Please enter a new letter");
inputLetter += c + " ";
if (inputLetter.length()<=50) {
inputLetter1 = inputLetter.substring(0, inputLetter.length());
} else {
inputLetter1 = inputLetter.substring(0, 50);
inputLetter2 = " " + inputLetter.substring(51, inputLetter.length());
}
boolean validLetter = word.checkLetter(c); boolean validLetter = word.checkLetter(c);
if (!validLetter) { if (!validLetter) {
current_step++; current_step++;
@ -31,7 +45,9 @@ public class HangMan {
void updateGraphicsView() { void updateGraphicsView() {
man.clear(); man.clear();
man.drawString(20 * scale, 60 * scale, "Word : " + word.userWord); man.drawString(20 * scale, 60 * scale, "Word : " + word.userWord, Color.DARK_GRAY, 20*scale);
man.drawString(20*scale, 260*scale, inputLetter1, Color.DARK_GRAY, 10*scale);
man.drawString(20*scale, 270*scale, inputLetter2, Color.DARK_GRAY, 10*scale);
for (int i = 1; i <= current_step; i++) { for (int i = 1; i <= current_step; i++) {
switch (i) { // dessin du pendu switch (i) { // dessin du pendu
case 1: case 1:
@ -86,7 +102,7 @@ public class HangMan {
} }
// System.out.print ("Do you want play another party ? (y/n) "); // System.out.print ("Do you want play another party ? (y/n) ");
// char answer = Input.readChar(); // char answer = Input.readChar();
char answer = Dialogs.getChar("Do you want play another party ? (y/n) "); char answer = Dialogs.getChar("Do you want to play another party ? (y/n) ");
if (answer != 'y' && answer != 'Y') { if (answer != 'y' && answer != 'Y') {
// System.out.println("Ok, see you later."); // System.out.println("Ok, see you later.");
Dialogs.displayMessage("Ok, see you later."); Dialogs.displayMessage("Ok, see you later.");