Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HangmanLogic {
- private String word;
- private String guessedLetters;
- private int numberOfFaults;
- private String letter;
- private String hiddenword;
- public HangmanLogic(String word) {
- this.word = word.toUpperCase();
- this.guessedLetters = "";
- this.numberOfFaults = 0;
- }
- public int numberOfFaults() {
- return this.numberOfFaults;
- }
- public String guessedLetters() {
- return this.guessedLetters;
- }
- public int losingFaultAmount() {
- return 12;
- }
- public void guessLetter(String letter) {
- this.letter =letter;
- if(guessedLetters.contains(this.letter)){ }
- else if(!word.contains(this.letter)){
- this.numberOfFaults+=1;
- this.guessedLetters+=letter;
- }else if(word.contains(letter)){
- this.guessedLetters+=letter;
- }
- // if the letter has already been guessed, nothing happens
- // it the word does not contains the guessed letter, number of faults increase
- // the letter is added among the already guessed letters
- }
- public String hiddenWord() {
- String hiddenword =word;
- hiddenword=hiddenword.replaceAll("[A-Z]","_");
- for (int i = 0; i < word.length(); i++){
- hiddenword=hiddenword.replace(hiddenword, "_");
- }
- System.out.println(hiddenword);
- while(!guessedLetters.equals(4)){
- if(word.contains(letter)){
- int letterplace= word.indexOf(letter);
- String hiddenword2= hiddenword.substring()
- }
- }
- // create the hidden word by interating through this.word letter by letter
- // if the letter in turn is within the guessed words, put it in to the hidden word
- // if the letter is not among guessed, replace it with _ in the hidden word
- // return the hidden word at the end
- return hiddenword;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment