Results 1 to 2 of 2
  1. #1
    trill is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Why does this program not end?

    Hi, This is my java minesweep game:

    Java Code:
    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 doesn't say that ever.
    Thanks.

  2. #2
    zoe
    zoe is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    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...

Similar Threads

  1. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 09:24 AM
  2. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  3. cannot run the program
    By amiey in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:13 AM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  5. I need help with this program
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •