/* PAT Assignment --- Word Guessing + Number pattern game
Charl Potgieter 10Pn
October / November 2009
*/
import javax.swing.*;
import java.util.*; // for random
public class GuessingGame1
{
public static void main (String [] args)
{
JOptionPane.showMessageDialog(null, "Welcome to the Guessing Game!");
for ( int j = 1; ; j = j ++ )
{
String menu, undscore1, undscore2, undscore3, undscore4, undscore5; //have underscores
Random ran = new Random();
char char1, char2, char3, char4, char5, inpChar;
String[] options = {"Word Guessing",
"Patterns Game ",
"Exit"
}; // Used to make options to select in the menu
menu = (String) JOptionPane.showInputDialog (null, " MENU", " Guessing Game", JOptionPane.PLAIN_MESSAGE, null, options, " "); //Starting menu
if (menu.equals (options [0]))
{
String word = JOptionPane.showInputDialog("Player 1: Please input a word (to a maximum of 5 characters), for single player type: 'random' "); //Ask for input, whether the user wants to make a word, or a random one
int rndChoice = (int)(Math.random()*14); // rndChoice is made for the switch to be able to randomly choose a word
//Code for user word
if (!word.equals("random"))
{
/* undscore1 = "_";
undscore2 = "_";
undscore3 = "_";
undscore4 = "_";
undscore5 = "_";
*/
String inpWord;
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
char1 = word.charAt(0);
char2 = word.charAt(1);
char3 = word.charAt(2);
char4 = word.charAt(3);
char5 = word.charAt(4);
if (inpChar == char1)
{
System.out.println("The word is: "+char1+"____ ");
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char2);
{
System.out.println("The word is: "+char1+char2+"___" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char3);
{
System.out.println("The word is: "+char1+char2+char3+"__" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char4);
{
System.out.println("The word is: "+char1+char2+char3+char4+"_" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char5);
{
System.out.println("The word is: "+char1+char2+char3+char4+char5 );
}
JOptionPane.showMessageDialog(null, "Congratulations, you have won! \n Returning to menu");
}
//Code for random word
if (word.equals("random"))
{
switch (rndChoice)
{
case 0:
word = "hello";
break;
case 1:
word = "kevin";
break;
case 2:
word = "charl";
break;
case 3:
word = "county";
break;
case 4:
word = "sweety";
break;
case 5:
word = "motor";
break;
case 6:
word = "edges";
break;
case 7:
word = "works";
break;
case 8:
word = "place";
break;
case 9:
word = "right";
break;
case 10:
word = "dudes";
break;
case 11:
word = "lucky";
break;
case 12:
word = "homes";
break;
}
undscore1 = "_";
undscore2 = "_";
undscore3 = "_";
undscore4 = "_";
undscore5 = "_";
String inpWord;
for ( int count = 1; ; count = count ++ )
{
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
char1 = word.charAt(0);
char2 = word.charAt(1);
char3 = word.charAt(2);
char4 = word.charAt(3);
char5 = word.charAt(4);
if (inpChar == char1)
{
System.out.println("The word is: "+char1+"____ ");
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char2);
{
System.out.println("The word is: "+char1+char2+"___" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char3);
{
System.out.println("The word is: "+char1+char2+char3+"__" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char4);
{
System.out.println("The word is: "+char1+char2+char3+char4+"_" );
}
inpWord = JOptionPane.showInputDialog("Please input a character that you want to guess");
inpChar = inpWord.charAt(0);
if(inpChar == char5);
{
System.out.println("The word is: "+char1+char2+char3+char4+char5 );
}
JOptionPane.showMessageDialog(null, "Congratulations, you have won! \n Returning to menu");
}
}
}
if (menu.equals (options [1]))
{
JOptionPane.showMessageDialog(null, "In this game you will be given 10 sequences of numbers that you will have to complete, you only have one try, its that easy!");
int patrn;
int rndNoChoice = (int)(Math.random()*14); // rndNoChoice is made for the switch to be able to randomly choose a pattern
switch (rndNoChoice)
{
case 0:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 15 ; 30 ; 45 ...."));
if (patrn == 60)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
/////////////////
case 1:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 10 ; 20 ; 30 ...."));
if (patrn == 40)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 2:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 1 ; 2 ; 3 ...."));
if (patrn == 4)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 3:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 7 ; 14 ; 21 ...."));
if (patrn == 28)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
/////////////////
case 4:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 8 ; 16 ; 24 ...."));
if (patrn == 32)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
/////////////////
case 5:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 2 ; 4 ; 6 ...."));
if (patrn == 8)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 6:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 12 ; 24 ; 36 ...."));
if (patrn == 48)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 7:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 1000 ; 750 ; 500 ...."));
if (patrn == 250)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 8:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 4 ; 8 ; 12 ...."));
if (patrn == 16)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 9:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 1000 ; 2000 ; 3000 ...."));
if (patrn == 4000)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
//////////////////
case 10:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 9 ; 18 ; 27 ...."));
if (patrn == 36)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
/////////////////
case 11:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 3 ; 6 ; 9 ...."));
if (patrn == 12)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
/////////////////
case 12:
patrn = Integer.parseInt(JOptionPane.showInputDialog("What is the next number: \n 23 ; 46 ; 69 ...."));
if (patrn == 92)
{
JOptionPane.showMessageDialog(null, "Correct!");
}
else
{
JOptionPane.showMessageDialog(null, "Incorrect!");
}
break;
}
//////////////////
}
if (menu.equals (options [2]))
{
JOptionPane.showMessageDialog(null,"Thank you for playing!! \n Credits: \t Charl Potgieter");
}
}
}
}