Results 1 to 5 of 5
  1. #1
    apaandmomo is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default how can i do this in the java word game i am making similar to battle ship

    hi i am making a word game in java. its objectives are similar to battleships. at the start of the game,5 words(or any number really) are randomly placed on locations on a GUI grid of 8 by 8. at first i had wanted to make words vary in length but i will do them of 3 letters each to keep it simple.the player tries to hit the words on the grid. If he hits a letter, a window pops up. in this window there will be the letter he hit and blank spaces for the rest of the letters. a hint about the word will also be displayed. the user has one chance to try and guess the word. if he manages it counts as a point and the word is sunk else the window closes and the game continues but the hit letter remains uncovered. i had no problem up till the later parts of making the game. I have created the grid in GUI and a word vector in another class. the main menu with the options of PLAY, HELP and ADD WORDS is functional and working. however i hit a road block. i cant figure out how to take the words from the vector and place them randomly on the grid :/ also the points methods that will keep track of the players points. how can i do this? also there is an odd number of words on the grid to avoid draws. please help any advice appriciated . one last thing is it possible to make a button uncklicable after it has been hit? thank you

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: how can i do this in the java word game i am making similar to battle ship

    For deploying words, break it down.

    You'll want a method that deploys all the words.
    This is the easy bit.
    Just loop over the array and call a deployWord(String) method.

    Now, you need to write the deployWord method.
    You'll need to describe your criteria for legal places to deploy a word.
    For example you can't deploy one too close to the right hand side of the grid, since the word wouldn't fit.

    As for making a button unclickable, they have a setEnabled method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    apaandmomo is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: how can i do this in the java word game i am making similar to battle ship

    Quote Originally Posted by Tolls View Post
    For deploying words, break it down.

    You'll want a method that deploys all the words.
    This is the easy bit.
    Just loop over the array and call a deployWord(String) method.

    Now, you need to write the deployWord method.
    You'll need to describe your criteria for legal places to deploy a word.
    For example you can't deploy one too close to the right hand side of the grid, since the word wouldn't fit.

    As for making a button unclickable, they have a setEnabled method.
    hi can u please explain in a bit more detail how i can do the econd method. i created the first method. how do i place a word onto an actual grid? thank you

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: how can i do this in the java word game i am making similar to battle ship

    Moved from Advanced Java.

    Whatever made you think this is an 'advanced' question?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: how can i do this in the java word game i am making similar to battle ship

    Quote Originally Posted by apaandmomo View Post
    hi can u please explain in a bit more detail how i can do the econd method. i created the first method. how do i place a word onto an actual grid? thank you
    You need to come up with some rules.
    Forget about the buttons, just come up with some rules about checking whether a particular location is valid.
    In order to check whether a position is valid it needs a model of the grid to work with. Note this is a model, not the grid of buttons itself. That button grid is simpyl a visual representation of the model.

    All this should be doable without any reference to a GUI whatsoever.
    Once you're happy that you have the population of this grid working, then you can use that grid to create the grid of buttons.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java stringtokenizer- making it reverse word
    By katiebear128 in forum New To Java
    Replies: 10
    Last Post: 09-29-2013, 04:20 PM
  2. Replies: 1
    Last Post: 03-21-2011, 04:12 AM
  3. BattleShip game ship on top of ship
    By linux1man in forum New To Java
    Replies: 2
    Last Post: 06-03-2009, 12:42 PM
  4. battle Ship game help!!
    By linux1man in forum New To Java
    Replies: 4
    Last Post: 06-03-2009, 01:47 AM

Tags for this Thread

Posting Permissions

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