package Testing; import java.util.Scanner; /* * @authors Jackson Pike, Kally Smith, Garrett Marion, Andrew Arthur, and Timothy Whalen */ public class HangMan { //Initialize Scanner and Variables Scanner input = new Scanner(System.in); String printUsed; int count; int word; int left; String num; //Helper method to add a line pace public void space() { System.out.println(); } //Main constructor public HangMan() { //Print The welcome message images.print("Welcome to HangMan the computer game."); images.o0(); //Start first(); first(); } //Method to get the current state of the noose public void getHangStat() { //Change count to an String and assign that value to num. This method references the class 'images' num = Integer.toString(count); if (num.equals("1")) { images.o1(); space(); } else if (num.equals("0")) { images.o0(); space(); } else if (num.equals("2")) { images.o2(); space(); } else if (num.equals("3")) { images.o3(); space(); } else if (num.equals("4")) { images.o4(); space(); } else if (num.equals("5")) { images.o5(); space(); } else if (num.equals("6")) { images.o6(); space(); } else if (num.equals("7")) { images.o7(); space(); } } //Method to print the current guessed letters public void printUsed(String used[]) { //Uses 'used' array to print out _ _ _ _ _ _ _ replacing the '_' with letters if guessed System.out.println(used[0] + " " + used[1] + " " + used[2] + " " + used[3] + " " + used[4] + " " + used[5] + " " + used[6]); } //Method defining the 'used' array public void first() { String used[] = new String[7]; //Assign all the values in the array to '_' to begin with used[0] = "_"; used[1] = "_"; used[2] = "_"; used[3] = "_"; used[4] = "_"; used[5] = "_"; used[6] = "_"; //Start the method 'Second' second(used); } //Method where all the action happens. public void second(String used[]) { //Happens while the word isn't guessed and they haven't guessed 7 times do { //Space method referenced above space(); //Print out the guess System.out.println("Enter your guess: "); space(); //Assign choice1 the value of user input String choice1 = input.next(); space(); //If statements that do the actual guessing if (choice1.equalsIgnoreCase("a")) { used[1] = "A"; word++; getHangStat(); printUsed(used); } else if (choice1.equalsIgnoreCase("G")) { used[0] = "G"; word++; getHangStat(); printUsed(used); } else if (choice1.equalsIgnoreCase("R")) { used[2] = "R"; used[3] = "R"; word++; word++; getHangStat(); printUsed(used); } else if (choice1.equalsIgnoreCase("E")) { used[4] = "E"; word++; getHangStat(); printUsed(used); } else if (choice1.equalsIgnoreCase("T")) { used[6] = "T"; used[5] = "T"; word++; word++; getHangStat(); printUsed(used); } else { count++; System.out.println("Try again"); getHangStat(); printUsed(used); if (count > 7) { break; } } left = 7 - count; space(); System.out.println("You have " + left + " guesses left."); } while (count < 7 && word < 7); if (count == 7) { System.out.print( "Ahhh crap. You didn't quite guess it soon enough. The man was hanged. The word was: G A R R E T"); } if (word == 7) { System.out.println("G A R R E T T"); System.out.println("Congrats, you saved him!!!"); } } public static void main(String[] args) { new HangMan(); } }