...

java minesweep game

blueandconfused
04-14-2005, 06:21 PM
why does this program not end?



import java.io.*;

public class MineSweep1
{
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
static private Bomb[] bmbArry = new Bomb[3];
static private char matrix[][];

public static void main(String[] args) throws IOException
{
char x,y;
matrix = new char[5][5];

for(int z = 0; z < 3; z++)
bmbArry[z] = new Bomb();
boolean explode;
explode = false;

for(x=0;x<5;x++)
for(y=0;y<5;y++)
matrix[x][y] = '*';
System.out.println("");

while (! (explode))
{
for(x=0;x<5;x++)
{
for(y=0;y<5;y++)
System.out.print(matrix[x][y]+" ");
System.out.println("");
}
explode = GetUserInput();
}
}

static boolean GetUserInput() throws IOException
{
int userX, userY;
System.out.println("Please enter an X position");
userX = Integer.parseInt(input.readLine());
System.out.println("Please enter an Y position");
userY = Integer.parseInt(input.readLine());

return IsItABomb(userX, userY);
}

static boolean IsItABomb(int X, int Y) throws IOException
{
for(int x=0;x<bmbArry.length;x++)
{
if((bmbArry[x].GetXpos() == X) && (bmbArry[x].GetYpos() == Y))

return GetUserInput();
}
return false;

}
}
when i run it and i hit a bomb, it is supposed to say "press any key to continue...." but it doesnt say that ever.

Jason
04-14-2005, 07:08 PM
you have a loop there that will never say there is a bomb...when your program should return true for IsItABomb you just call getUserInput again and that goes back and calls IsItABomb again...there is no "return true;" for a bomb...


Jason



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum