Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 05:49 AM
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
Why does this program not end?
Hi, This is my java minesweep game:

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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 08:22 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a program within a program gibsonrocker800 New To Java 5 05-12-2008 09:24 AM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 03:40 PM
cannot run the program amiey New To Java 1 11-20-2007 05:13 AM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM
I need help with this program Daniel Advanced Java 2 07-04-2007 06:14 AM


All times are GMT +3. The time now is 10:52 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org