• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Drawing a Character Grid

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I'm trying to create Word Search type of game where words are hidden in a bunch of letters. I'd like to know whats the best way to go about it. I mean do I create a char grid. How do I draw them on the screen (I mean like using drawString(.. or something). I know how to create a line grid using drawLine but I am kind of stuck in this part, creating the grid. Any kind of resources or guidance would help a lot.

Thanks
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you could use either drawString() or pack all of the characters into a single char[] and use drawChars(); it's up to you. You set the font on the Graphics before drawing the first letter, and go from there. If you can calculate the correct points for the gird lines, doing the same with a slight adjustment should work for the characters.

I recommend experimenting with it a little and see how far you can get. Come back if you get stuck and post what you have with some specific questions.

Welcome to JavaRanch!
 
Darrell Morello
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the welcome

Heres what I have gone to so far...
This is just the Grid panel which will be added to the main frame.



It just manages to draw a grid and insert letters. Now I'm looking for a way to select words so that the point where I press the mouse button and releases it is matched with the starting and ending columns and rows of the word respectively. It then marks the word as found. Any ideas would help.

Thanks again.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Audio Slave"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You basically need to turn mouse events into word selection events, as it appears you've started above. As a first design I would do the following. Note that a grid cell is denoted by its row and column.
  • mousePressed(): Save starting grid cell, change background of starting cell to some highlight color. Set tracking cell to starting cell.
  • mouseMoved(): If new cell is the same as the tracking cell -- user is in the same cell as the last update, exit method without doing anything more. Otherwise, set tracking cell to new cell and set the background colors of all cells between the starting and tracking cell to the highlight color. If the line of cells from starting cell to tracking cell don't make up a valid line (aren't perfectly horizontal, vertical, or diagonal), highlight only the starting cell. Make sure you clear the backgrounds of the previously highlighted cells if they shouldn't still be highlighted.
  • mouseReleased(): Clear all highlighting. If the line of cells from starting cell to tracking cell is valid, the user has selected a word. Perform any other validation you need to do and exit.
  •  
    Your mind is under my control .... your will is now mine .... read this tiny ad
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic