Results 1 to 2 of 2

Thread: while loop help

  1. #1
    kathyla18 is offline Member
    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0

    Default while loop help

    hi , i created the game battleship but im supposed to end it after the 17th hit 5 hits for ship A 4 for ship B 3 for ship P 3 for ship D and 2 for ship S. What i did was to create a while loop
    while i< 17
    //my board is here
    if (gameBoard.guessPosition(row, column)== true) {
    i++;
    }

    but i realized that if i do that then if the user hits the same ship 17 times the game ends too. I dont know how to make it end after all of the ships have been hit. Any help will be appreciated. Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    An array of booleans set to true when that ship part has been hit, and a counter to keep track of how many times a value actually changes.

Similar Threads

  1. Help w/ loop
    By iWonder in forum New To Java
    Replies: 17
    Last Post: 11-20-2008, 01:39 AM
  2. While loop
    By sjhentges in forum New To Java
    Replies: 11
    Last Post: 11-04-2008, 05:26 PM
  3. Need help with While Loop
    By mrdestroy in forum New To Java
    Replies: 14
    Last Post: 10-20-2008, 03:29 PM
  4. do...while loop
    By eva in forum New To Java
    Replies: 16
    Last Post: 01-31-2008, 07:44 AM
  5. can you help me with this for loop?
    By java_fun2007 in forum New To Java
    Replies: 6
    Last Post: 12-22-2007, 11:20 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
  •