• Advertisement
Sign in to follow this  

Getting user input for word search game

This topic is 1521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need some help in getting user input for a word search game I am making in Java using swing. I have everything working and displaying properly such as the game board and the words the user has to find. I am using a 2D array of JPanels to display the individual letters. What I would like to do is draw an oval where the starting point is where the user thinks the beginning of the word is, and then release it when the user is over the end of the word. How would I get the letters of the word in between the clicks? Any help would be greatly appreciated.

 

Here is the link to my pastebin where the code is for all the classes I am using.

Share this post


Link to post
Share on other sites
Advertisement

Assumption: You know which tile in the 2D array the user started with and which he ended with.

Assumption: It is only possible to highlight horizontal, vertical or 45 degrees diagonal words.

 

The amount of tiles to check in the x or y direction is the absolute value of (end - start) -- or (start - end) -- these are equivalent.

If the number of tiles is greater than zero in both directions, you have diagonal movement. Note that you will also have the same number of tiles in each direction.

If the number of tiles is greater than zero in 1 direction only, you have either vertical or horizontal selection.

 

In both cases, you'll want to loop over some tiles.

Starting with the user's start tile*, store that tile's letter + every tile's letter until you reach the end tile.

For pure horizontal or vertical selections, increment the corresponding x or y variable in your 2D array.

For diagonal selections, increment both the x and y variables in your 2D array.

 

After finishing the loop, you should have all selected tile letters stored, which you can use to check against valid words.

 

 

*Potentially, always start with the top-most and left-most, if all words are written top to bottom and left to right.

 

Also, you could probably have kept to using your previous thread: http://www.gamedev.net/topic/650356-help-with-some-problems-with-word-search-game/

Share this post


Link to post
Share on other sites


In both cases, you'll want to loop over some tiles.

Starting with the user's start tile*, store that tile's letter + every tile's letter until you reach the end tile.

 

That was exactly what I was looking for. Thank you. Not sure why I was having programmer's block.

 


Also, you could probably have kept to using your previous thread: http://www.gamedev.net/topic/650356-help-with-some-problems-with-word-search-game/

 

Sorry, wasn't sure if I should have posted this question in there or not.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement