Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- char[] word1 = {'h', 'o', 't', 'e', 'l'};
- char[] word2 = {'c', 'l', 'i', 'f', 'f'};
- char[] word3 = {'b', 'e', 'a', 'c', 'h'};
- char[] word4 = {'r', 'e', 'a', 'l', 'm'};
- char[] word5 = {'a', 't', 't', 'i', 'c'};
- char[] finalWord = null;
- Random rand = new Random();
- int rand_int1 = rand.nextInt(6);
- if (rand_int1 == 1) {
- finalWord = word1;
- } else if (rand_int1 == 2) {
- finalWord = word2;
- } else if (rand_int1 == 3) {
- finalWord = word3;
- } else if (rand_int1 == 4) {
- finalWord = word4;
- } else {
- finalWord = word5;
- }
- String misses = "";
- int maxTries = 10;
- int numberOfGuesses = 0;
- char[] guess = {'_', '_', '_', '_', '_'};
- while (true) {
- System.out.println("_=_=_=_=_=_=_=_=_=_=_=_=_=_=_");
- System.out.println();
- System.out.print("Word: ");
- for (int i = 0; i < guess.length; i++) {
- System.out.print(guess[i] + " ");
- }
- System.out.println("\n\nMisses: " + misses);
- if ((Arrays.equals(finalWord, guess))){
- System.out.println("YOU GOT IT!");
- break;
- }
- if (numberOfGuesses == maxTries) {
- System.out.println("You used your " + maxTries + " number of tries");
- System.out.println("You did not guess the word correctly");
- break;
- }
- System.out.print("\nGuess: ");
- Scanner keyboard = new Scanner(System.in);
- String input = keyboard.next();
- int total = 0;
- for (int i = 0; i < guess.length; i++) {
- if (finalWord[i] == input.charAt(0)) {
- guess[i] = input.charAt(0);
- total++;
- }
- }
- if (total == 0) {
- misses = misses + " " + input.charAt(0);
- }
- numberOfGuesses = numberOfGuesses + 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement