Guest User

Untitled

a guest
Sep 17th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. public class HangmanLogic {
  2.  
  3.     private String word;
  4.     private String guessedLetters;
  5.     private int numberOfFaults;
  6.     private String letter;
  7.     private String hiddenword;
  8.  
  9.     public HangmanLogic(String word) {
  10.         this.word = word.toUpperCase();
  11.         this.guessedLetters = "";
  12.         this.numberOfFaults = 0;
  13.     }
  14.  
  15.     public int numberOfFaults() {
  16.         return this.numberOfFaults;
  17.     }
  18.  
  19.     public String guessedLetters() {
  20.         return this.guessedLetters;
  21.     }
  22.  
  23.     public int losingFaultAmount() {
  24.         return 12;
  25.     }
  26.  
  27.     public void guessLetter(String letter) {
  28.         this.letter =letter;
  29.         if(guessedLetters.contains(this.letter)){ }
  30.          
  31.         else if(!word.contains(this.letter)){
  32.             this.numberOfFaults+=1;
  33.             this.guessedLetters+=letter;
  34.              
  35.         }else if(word.contains(letter)){
  36.             this.guessedLetters+=letter;
  37.              
  38.         }
  39.          
  40.         // if the letter has already been guessed, nothing happens
  41.  
  42.         // it the word does not contains the guessed letter, number of faults increase
  43.         // the letter is added among the already guessed letters
  44.     }
  45.  
  46.     public String hiddenWord() {
  47.         String hiddenword =word;
  48.          
  49.         hiddenword=hiddenword.replaceAll("[A-Z]","_");
  50.          
  51.         for (int i = 0; i < word.length(); i++){
  52.             hiddenword=hiddenword.replace(hiddenword, "_");
  53.         }
  54.          
  55.         System.out.println(hiddenword);
  56.          
  57.         while(!guessedLetters.equals(4)){
  58.              
  59.              if(word.contains(letter)){
  60.                 int letterplace= word.indexOf(letter);
  61.                  String hiddenword2= hiddenword.substring()
  62.              }
  63.              
  64.         }
  65.         // create the hidden word by interating through this.word letter by letter
  66.         // if the letter in turn is within the guessed words, put it in to the hidden word
  67.         // if the letter is not among guessed, replace it with _ in the hidden word
  68.  
  69.         // return the hidden word at the end
  70.         return hiddenword;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment