I have a game were the computer tries to guess the users number by using <, >, and = to tell the computer if your number is higher(>) lower(<) or if that is your number(=) . Also, it should keep track of the average number of guesses it takes per game and the number of games you play. But, so far all I can do is get it to run one game before it quits and I need it to be able to run more than one game I think I'm not doing the loop part right, but I have no idea how to fix it.
Here is what I have so far.....
import javax.swing.JOptionPane;
public class TestGame
{
public static void main(String[] args)
{
int[] games = {0, 0};
randomGame(games);
JOptionPane.showMessageDialog(null, "You played " + games[0] + " games with a " + games[1] + " average amount of tries.");
System.exit(0);
}
public static int[] randomGame(int[] array)
{
String input;
int guess, a=50, b=100, c=0, d=0, total=0, attempt=0;
char repeat;
{
JOptionPane.showMessageDialog(null, "Guess a number between 1 and 100 and prepare to start the game.");
total ++;
do
{
input = JOptionPane.showInputDialog( "How about " + a + "(<,=,>)?");
attempt ++;
if (input.equals(">"))
{
d = (b - a) / 2 + a;
c = a;
a = d;
}
else if (input.equals("<"))
{
d = a - ((a-c)/2);
b = a;
a = d;
}
else if (input.equals("="))
{
JOptionPane.showMessageDialog(null, "Good game!");
}
total =+ attempt;
}while (!input.equals("="));
{array[0]++;
input = JOptionPane.showInputDialog ("Would you like to play again (y/n)?");
repeat = input.charAt(0);
}while (repeat == 'y');
array[1] = (total/array[0]);
return array;
}
}
}
Any help at all would be apreciated
Thank You