-1

I have been working on a Words Formation game (sample: http://www.popcap.com/games/bookworm/online) for quite long. Everything is done, except for one last thing that I can not figure out how to implement.

In short, I am displaying a 2D grid of Jbuttons with letters one them (I have implemented a graphical version of JButton). The user has to form words from the random letters on the buttons, and the score is added. Now when the user can no longer form any words, I want the game to end. The idea I tried using to implement this is as follows:

I store ALL the coordinates of the grid in an ArrayList (I will call this AllCoordinates). Then, I store the coordinates of the selected JButtons in a separate ArrayList (I will call this Coordinates). I compare the two lists, and store the coordinates in the ArrayList AllCoordinates that do not exist in Coordinates. I do not know how I can form various words with so many random coordinates. Could someone help me with a way of doing this?

If you have any better ideas of doing this, I would be grateful for your input.

PS
I am sorry for not posting the code. It is too long and complicated to be posted here

Thanks :)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
craig-nerd
  • 718
  • 1
  • 12
  • 32
  • 5
    1. How do you define a "word"? Is it an English word that must be found in some reference, such as a dictionary? 2. Why not show pertinent code and how would pertinent code be too long to display here? I would assume that you've separated your program logic from your GUI, and so there would be no need to post GUI code for this question, since it just pertains to program logic. – Hovercraft Full Of Eels Sep 11 '15 at 22:14

1 Answers1

1

Do not "form various words with so many random coordinates." Instead,

  1. On initialization, read a sorted dictionary into a List<String> named wordList.

  2. Use JToggleButton instances in the grid, as outlined here and here; if needed, you can calculate coordinates as shown here.

  3. In an ItemListener shared by the buttons, form a String holding the selectedWord as the letters are selected.

  4. Use Collections.binarySearch() to determine if wordList contains the selectedWord.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045