Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hangman;
- import java.util.*;
- import javax.swing.*;
- public class HangMan {
- public static void main(String[] args) {
- HangMan Caller = new HangMan();
- Caller.Work();
- }
- protected void Work() {
- String[] Words = new String[]{"Dog", "Cat", "Elephant", "Pants", "Guitar", "Pasta", "Donkey", "Xylophone", "Paper", "Sequoia"};
- String Word = Words[(int) (Math.random() * ((9 - 0) + 1))];
- ArrayList<Character> Dashes = new ArrayList<Character>();
- ArrayList<Character> Guessed = new ArrayList<Character>();
- for (int a = 0; a < Word.length(); a++) {
- Dashes.add('_');
- }
- for (int b = 0; b < Word.length(); b++) {
- ImageIcon icon = new ImageIcon("HagMan" + b + ".jpeg");
- String Search = JOptionPane.showInputDialog(null, Dashes + "\nWhat letter do you think is next?\n ",
- "Find Interest Rate", JOptionPane.PLAIN_MESSAGE, icon, null, "").toString();
- char Guess = Search.charAt(0);
- Boolean FlawedAnswer = false;
- if (Search.length() != 1) {
- JFrame GG = new JFrame();
- JOptionPane.showMessageDialog(GG, "That wasn't a char, try again.");
- FlawedAnswer = true;
- }
- if (Guessed.contains(Guess)) {
- JFrame Goofed = new JFrame();
- JOptionPane.showMessageDialog(Goofed, "You've already guessed that letter, try again.");
- FlawedAnswer = true;
- }
- for (int x = 0; x < Dashes.size(); x++) {
- if (Word.charAt(x) == Guess && FlawedAnswer != true) {
- b--;
- Guessed.add(Guess);
- Dashes.set(x, Guess);
- String word = new String();
- for (char c : Dashes) {
- word = word + c;
- }
- if (word.equals(Word)) {
- JFrame GG = new JFrame();
- JOptionPane.showMessageDialog(GG, "You win!");
- System.exit(0);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement