Results 1 to 7 of 7

Thread: Battleship

  1. #1
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Battleship

    Hello everyone

    I'm making a battleship game for school. I have created a String array with al the possibble coordinates eg.{"1a",1b","1c",...}. Now a random generator picks random strings from the array. Now i have a problem. If the computer picks a string from the array i would like to delete it so the computer can't pick 2 times the same coordinate. I thougt about making a seccond array, an arraylist, where all the coordinates that already are selected from the other array by the generator are put in, but then how can i make the generator select a coordinate from the string and then control it by searching in the arraylist if it hasn't already been generated?

    maybe someone can help me or have an better idea.
    thx in advance
    greetings
    Last edited by Matthieu105; 11-28-2012 at 11:43 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: Battleship

    Why not have a String List where you pick the random coordinates from? After you have picked a coordinate you can delete is from the List so you can't pick it again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Battleship

    indeed, thats a much better idea, thanks :)

  4. #4
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Battleship

    Can someone pls make JosAH example in java. i'm trying to do but I don't know how i have to do it exactly :/

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: Battleship

    Read the API documentation for the List<T> interface and pay special attention to the remove( ... ) methods. (b.t.w. we are not going to do your work for you; you want to implement a battleship program, not us ...)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Matthieu105 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Battleship

    no problem, I already found it myself :)

  7. #7
    musclecode is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Battleship

    Look at book "Head First Java" there's creating game like this step by step ;)

Similar Threads

  1. Battleship program
    By buckbuck2 in forum New To Java
    Replies: 2
    Last Post: 11-28-2012, 02:57 AM
  2. Help with Battleship Game
    By Lucid15 in forum New To Java
    Replies: 59
    Last Post: 04-11-2012, 07:37 PM
  3. Battleship UML help
    By Lucid15 in forum New To Java
    Replies: 0
    Last Post: 03-12-2012, 04:15 AM
  4. battleship in java
    By matthewandalex5 in forum Advanced Java
    Replies: 2
    Last Post: 03-01-2012, 03:13 PM
  5. battleship in java
    By matthewandalex5 in forum New To Java
    Replies: 2
    Last Post: 03-01-2012, 06:09 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
  •