Results 1 to 4 of 4
  1. #1
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default How to make a game quit in BlueJ after entering a room

    I am new to BlueJ and programming and I have a game application that runs exactly how I want it too except I want the game to quit once I enter a room called "DungeonRoom" which extends the "Room" class. Here is my code for the DungeonRoom:

    Java Code:
    import java.util.ArrayList;
    
    public class DungeonRoom extends Room
    {
     
        private boolean isAlive = false;
        private boolean finished = false;
        /**
         * Constructor for objects of class DungeonRoom
         */
        public DungeonRoom(String description)
        {
            super(description);
           while (! finished) {
                //Command command = parser.getCommand();
                //finished = processCommand(command);
                if (hasDied()) finished = true;
           }
            System.out.println("Thank you for playing.  Good bye.");      
        }
        
       public boolean hasDied() {return isAlive == false;}
        public void die() {isAlive = false;}
    
    }
    Currently when I try to run my game after adding the while statement it completely freezes and I have to Crtl-alt-delete End the task. Can anyone guide me on how I can have this game quit once I get into this room.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    System.exit(0) ends the program. I don't think it will close the game though.

    Is your game displayed in a GUI or text based through command prompt or displayed in an IDE or what?
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    its using BlueJ in the terminal window so that would be command prompt, right?

  4. #4
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    when i tried to add the System.exit(0); to the code and removing all the rest of the code, so basically all I had was

    public DungeonRoom(String description)
    {
    super(description);
    System.exit(0);
    }

    The game object does not even get created on the workbench.

Similar Threads

  1. how to make mastermind game
    By javabeginer in forum New To Java
    Replies: 10
    Last Post: 04-14-2009, 02:11 AM
  2. Quit Button, Load new Frame, Timer Code
    By IHateNetbeans in forum New To Java
    Replies: 1
    Last Post: 03-18-2009, 03:58 PM
  3. Replies: 1
    Last Post: 08-09-2008, 11:55 AM
  4. help using BlueJ
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:07 AM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 02:28 PM

Posting Permissions

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