Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package hangman;
  2.  
  3. import java.util.*;
  4. import javax.swing.*;
  5.  
  6. public class HangMan {
  7.  
  8.     public static void main(String[] args) {
  9.         HangMan Caller = new HangMan();
  10.         Caller.Work();
  11.     }
  12.  
  13.     protected void Work() {
  14.         String[] Words = new String[]{"Dog", "Cat", "Elephant", "Pants", "Guitar", "Pasta", "Donkey", "Xylophone", "Paper", "Sequoia"};
  15.  
  16.         String Word = Words[(int) (Math.random() * ((9 - 0) + 1))];
  17.         ArrayList<Character> Dashes = new ArrayList<Character>();
  18.         ArrayList<Character> Guessed = new ArrayList<Character>();
  19.  
  20.         for (int a = 0; a < Word.length(); a++) {
  21.             Dashes.add('_');
  22.         }
  23.  
  24.         for (int b = 0; b < Word.length(); b++) {
  25.             ImageIcon icon = new ImageIcon("HagMan" + b + ".jpeg");
  26.             String Search = JOptionPane.showInputDialog(null, Dashes + "\nWhat letter do you think is next?\n ",
  27.                     "Find Interest Rate", JOptionPane.PLAIN_MESSAGE, icon, null, "").toString();
  28.  
  29.             char Guess = Search.charAt(0);
  30.             Boolean FlawedAnswer = false;
  31.  
  32.             if (Search.length() != 1) {
  33.                 JFrame GG = new JFrame();
  34.                 JOptionPane.showMessageDialog(GG, "That wasn't a char, try again.");
  35.                 FlawedAnswer = true;
  36.             }
  37.  
  38.             if (Guessed.contains(Guess)) {
  39.                 JFrame Goofed = new JFrame();
  40.                 JOptionPane.showMessageDialog(Goofed, "You've already guessed that letter, try again.");
  41.                 FlawedAnswer = true;
  42.             }
  43.  
  44.             for (int x = 0; x < Dashes.size(); x++) {
  45.  
  46.                 if (Word.charAt(x) == Guess && FlawedAnswer != true) {
  47.                     b--;
  48.                     Guessed.add(Guess);
  49.                     Dashes.set(x, Guess);
  50.                     String word = new String();
  51.                    
  52.                     for (char c : Dashes) {
  53.                         word = word + c;
  54.                     }
  55.                    
  56.                     if (word.equals(Word)) {
  57.                         JFrame GG = new JFrame();
  58.                         JOptionPane.showMessageDialog(GG, "You win!");
  59.                         System.exit(0);
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement