Greetings from Greece.
We got a Hangman assignment for my Class at Java.
I m just a begginer.And the whole input/output thing is done either by console (system.out.println) or with JOptionPane.
So here is my code
import javax.swing.JOptionPane;
import java.util.*;
public class Hangman
{
public static void main (String a [])
{
//////////////////
String word = "";
int guesses;
//////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String difficulty = JOptionPane.showInputDialog ("Select difficulty : 1 for easy -- 2 for normal -- 3 for hard");
int intDifficulty = Integer.parseInt(difficulty);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String easyDictionary [] = { " abstraction ", " ambiguous ", " arithmetic ", " backslash " , " bitmap", " circumstance", " combination", " consequently", " consortium", " decrementing", " dependency", " disambiguate", " dynamic", " encapsulation", " equivalent", " expression", " facilitate", " fragment", " hexadecimal", " implementation", " indistinguishable", " inheritance", " internet", " java", " localization", " microprocessor", " navigation", " optimization", " parameter", " patrick", " pickle", " polymorphic", " rigorously", " simultaneously", " specification", " structure", " lexical", " likewise", " management", " manipulate", " mathematics", " hotjava", " vertex", " unsigned", " traditional" };
String normalDictionary [] = {"boy", "girl", "mother", "father", "sister", "love", "sky", "wind", "water", "study", "ball",
"cat", "dog", "puppy", "kitten", "apple", "pear", "lemon", "mango", "peach", "apricot", "chips", "steak", "fries", "cheese",
"patatoe", "wedge", "heel", "hand", "foot", "arm", "leg", "nose", "face", "mouth", "tongue", "fingers", "toes", "line", "space",
"phone", "cord", "core", "grass", "trees", "birds", "animals", "lazy", "funny", "king", "queen", "heart", "heat", "cold", "sun",
"moon", "movie", "theater", "hairy", "big", "small", "large", "huge", "pig", "donkey", "cow", "chicken", "pizza", "bread", "stones",
"sticks", "leaves", "letters", "alphabet", "soup", "hungry", "tired", "sleepy", "noisy", "caring", "friends", "month", "day", "light"};
String hardDictionary [] = { "toothbrush", "savings", "bank", "account", "teller", "paper", "pencil", "tea", "coffee", "spirit", "ghost", "can", "melon", "necklace",
"screen", "baloon", "string", "calendar", "work", "toys", "kids", "school", "class", "campus", "freedom", "liberty", "happiness",
"university", "message", "marker", "crayon", "eraser", "music", "lyrics", "songs", "ballads", "shapes", "triangle", "circle", "rectangle",
"square", "oval", "show", "video", "player", "team", "sport", "basketball", "football", "soccer", "softball", "baseball", "tennis",
"hockey", "lacrosse", "volleyball", "circut", "blade", "scratch", "hit", "home", "house", "safe", "safety", "number", "count", "bear",
"goose", "lama", "panda", "lion", "tiger", "cheetah", "computer", "crackers", "rice", "fan", "shoes", "book", "story", "princess",
"prince", "jester", "court", "jury", "judge", "bench", "scandal", "name", "newspaper", "press", "shove", "tear", "cry", "magic", "tricks",
"cereal", "breakfast", "lunch", "dinner", "main", "course", "fork", "spoon", "knife", "lamp", "desk", "bottle", "highlighter", "cap",
"medicine", "six", "seven", "flower", "rose", "petal"};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
Scanner letterProvided = new Scanner(System.in);
String pickedArray [] = {""};
String letter;
///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (intDifficulty == 1 )
{
Collections.shuffle( Arrays.asList ( easyDictionary ));
word = ( easyDictionary[1] );
System.out.println( "Easy huh?" );
}
else if (intDifficulty == 2)
{
Collections.shuffle( Arrays.asList (normalDictionary ));
word = ( normalDictionary[1] );
System.out.println( "At last!A normal guy." );
}
else if (intDifficulty == 3)
{
Collections.shuffle( Arrays.asList ( hardDictionary ));
word =( hardDictionary[1] );
System.out.println ( "You think you are a tough guy?" );
}
else
{
JOptionPane.showMessageDialog( null,"ERROR TYPE #1: Please input 1 , 2 or 3 to select Hangman's difficulty!" , "Error!" ,JOptionPane.ERROR_MESSAGE );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
String [] hidden = new String [word.length()];
///////////////////////////////////////////////
///////////////////////////////////////////////
for ( int i = 0 ; i < word.length() ; i++ )
{
hidden[i] = "_";
}
///////////////////////////////////////////////
/////////////////////////////////////////////////////////////
System.out.print("Please enter a letter in lower case only!");
letter = letterProvided.nextLine();
}
}
I got some problems here.
First I need my word to be in an array so to check if the input is correct or not.With an array ill be able to check double letters also! So I just dont know what to do with the input I got from
System.out.print("Please enter a letter in lower case only!");
letter = letterProvided.nextLine();
Secondly i need a counter about maximum Tries , but i cant figure out where i should put the loop and do
maximumTries--;
Thank you a lot for reading my post =)