Results 1 to 6 of 6
  1. #1
    sarevok9 is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default How do I "end" a game?

    Let's assume for a moment you're programming a game, how do you go about ending it in the event that the win condition is achieved? Right now, my rough idea is this. (this is all going to be pseudocode) I'm just putting this here to make sure my logic is sound before I try coding this in a few hours after I complete all my other game stuff



    boolean isPlayerTurn=false;
    boolean isCPUTurn= false;
    boolean isGame=true;
    while (isGame){
    isCPUTurn = true;
    while (isCPUTurn){
    //do cpu turn stuff
    //assuming it make it through everything
    //Do I check for win conditions in each players loop, if so how do I break the loop since it's a nested while?
    isCPUTurn = false;
    }
    isPlayerTurn= true;
    while(isPlayerTurn){
    //Do player turn stuff
    //end turn if all goes smoothly
    isPlayerTurn=false;
    }

    That's my current turn system in a nutshell, but lets assume that it's in the CPU turn and they score a winning hit, if I do an if that generates a break, won't it just break from the CPUTurn loop and not from isGame? Is my logic totally off here? Help?

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    6

    Default

    I am not pretty sure but You can try System.exit() .

    Hope this help.
    Mak
    (Living @ Virtual World)

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    JFrame or console? Either way you could just call a method that checks to see if the winning hit was made. If yes, then call end game. Which depending on your method of display would differ.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    sarevok9 is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    I suppose that would work, thanks a lot dark =P

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Personally thats how I'm doing it for my mini RPG I'm writing. If you need any more questions answered, feel free to ask.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  6. #6
    sarevok9 is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    Quote Originally Posted by Dark View Post
    Personally thats how I'm doing it for my mini RPG I'm writing. If you need any more questions answered, feel free to ask.
    I just opened a new thread with one that is making me claw at my eyes, so if you're able, please take a look.

Similar Threads

  1. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. Java Applet Help - Making "Snake" Game
    By Alphimeda in forum Java Applets
    Replies: 15
    Last Post: 04-04-2010, 05:39 PM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •