Jump to content

  • Log In with Google      Sign In   
  • Create Account


Getting user input for word search game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Manhattanisgr8   Members   -  Reputation: 477

Like
0Likes
Like

Posted 23 November 2013 - 09:27 PM

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.


Cpl Alt, Travis A

USMC


Sponsor:

#2 Lactose!   GDNet+   -  Reputation: 2515

Like
1Likes
Like

Posted 24 November 2013 - 06:24 AM

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/



#3 Manhattanisgr8   Members   -  Reputation: 477

Like
0Likes
Like

Posted 24 November 2013 - 01:41 PM


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.


Cpl Alt, Travis A

USMC





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS