Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int counter = 1;
- while (true) {
- System.out.print("Word is * ");
- currentWord = "";
- for (int i = 0; i < marks.length; i++) {
- System.out.print(marks[i]);
- }
- System.out.print("\nGuess a letter * ");
- userInput = input.nextLine();
- if (userInput.length() != 1) {
- System.out.println("Invalid guess" + userInput);
- } else if (lettersGuessed.contains(userInput.charAt(0))) {
- System.out.println("You already guessed that character: " + userInput);
- } else if (!randomWord.contains(userInput)) {
- numberofGuesses++;
- System.out.println("Would you like a hint? y or n");
- hintanswer = input.nextLine();
- if ("y".equals(hintanswer)) {
- try{
- System.out.println("Word does not contain: " + userInput);
- System.out.println("In total you have " + wordList.get(randomInt).getNoOfHints() +
- ". This is your hint #" + counter++);
- String line = Files.readAllLines(Paths.get("hints.txt")).get(wordList.get(randomInt).getHints().get(0) - 1);
- System.out.println("Hint: " + line);
- wordList.get(randomInt).getHints().remove(0);
- }catch(IndexOutOfBoundsException e){
- if(counter > wordList.get(randomInt).getNoOfHints() + 1){
- System.out.println("You have ran out of hints. Here is your last hint: ");
- char firstLetter = randomWord.charAt(0);
- char lastLetter = randomWord.charAt(randomWord.length() - 1);
- System.out.println("The first letter of the word is " + firstLetter+ " and the last letter "
- + "of the word is " + lastLetter);
- continue;
- }
- }
- /* if(counter > wordList.get(randomInt).getNoOfHints() + 1){
- System.out.println("You have ran out of hints. Here is your last hint: ");
- char firstLetter = randomWord.charAt(0);
- char lastLetter = randomWord.charAt(randomWord.length() - 1);
- System.out.println("The first letter of the word is " + firstLetter+ "and the last letter"
- + "of the word is " + lastLetter);
- }*/
- } if ("n".equals(hintanswer)) {
- System.out.println();
- }
- } else if (randomWord.contains(userInput)) {
- lettersGuessed.add(userInput.charAt(0));
- currentWord = "";
- for (int i = 0; i < randomWord.length(); i++) {
- if (randomWord.charAt(i) == userInput.charAt(0)) {
- marks[i] = "" + userInput.charAt(0);
- }
- currentWord += marks[i];
- }
- }
- if (currentWord.equals(randomWord)) {
- break;
- }
- }
- System.out.println(randomWord + " was guessed after " + numberofGuesses + " missed attempts");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement