Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. int counter = 1;
  2. while (true) {
  3.  
  4. System.out.print("Word is * ");
  5. currentWord = "";
  6. for (int i = 0; i < marks.length; i++) {
  7.  
  8. System.out.print(marks[i]);
  9.  
  10. }
  11.  
  12. System.out.print("\nGuess a letter * ");
  13. userInput = input.nextLine();
  14. if (userInput.length() != 1) {
  15.  
  16. System.out.println("Invalid guess" + userInput);
  17.  
  18. } else if (lettersGuessed.contains(userInput.charAt(0))) {
  19.  
  20. System.out.println("You already guessed that character: " + userInput);
  21.  
  22. } else if (!randomWord.contains(userInput)) {
  23.  
  24. numberofGuesses++;
  25. System.out.println("Would you like a hint? y or n");
  26. hintanswer = input.nextLine();
  27. if ("y".equals(hintanswer)) {
  28.  
  29. try{
  30. System.out.println("Word does not contain: " + userInput);
  31. System.out.println("In total you have " + wordList.get(randomInt).getNoOfHints() +
  32. ". This is your hint #" + counter++);
  33. String line = Files.readAllLines(Paths.get("hints.txt")).get(wordList.get(randomInt).getHints().get(0) - 1);
  34.  
  35. System.out.println("Hint: " + line);
  36. wordList.get(randomInt).getHints().remove(0);
  37.  
  38. }catch(IndexOutOfBoundsException e){
  39.  
  40. if(counter > wordList.get(randomInt).getNoOfHints() + 1){
  41. System.out.println("You have ran out of hints. Here is your last hint: ");
  42. char firstLetter = randomWord.charAt(0);
  43. char lastLetter = randomWord.charAt(randomWord.length() - 1);
  44. System.out.println("The first letter of the word is " + firstLetter+ " and the last letter "
  45. + "of the word is " + lastLetter);
  46. continue;
  47. }
  48. }
  49. /* if(counter > wordList.get(randomInt).getNoOfHints() + 1){
  50.  
  51. System.out.println("You have ran out of hints. Here is your last hint: ");
  52. char firstLetter = randomWord.charAt(0);
  53. char lastLetter = randomWord.charAt(randomWord.length() - 1);
  54. System.out.println("The first letter of the word is " + firstLetter+ "and the last letter"
  55. + "of the word is " + lastLetter);
  56.  
  57. }*/
  58. } if ("n".equals(hintanswer)) {
  59.  
  60. System.out.println();
  61.  
  62. }
  63. } else if (randomWord.contains(userInput)) {
  64.  
  65. lettersGuessed.add(userInput.charAt(0));
  66. currentWord = "";
  67. for (int i = 0; i < randomWord.length(); i++) {
  68.  
  69. if (randomWord.charAt(i) == userInput.charAt(0)) {
  70.  
  71. marks[i] = "" + userInput.charAt(0);
  72.  
  73. }
  74.  
  75. currentWord += marks[i];
  76.  
  77. }
  78. }
  79.  
  80. if (currentWord.equals(randomWord)) {
  81.  
  82. break;
  83.  
  84. }
  85. }
  86.  
  87. System.out.println(randomWord + " was guessed after " + numberofGuesses + " missed attempts");
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement