1
\$\begingroup\$

I am making a game where the user is given a letter on screen such as the below image enter image description here

The user then uses the mouse to draw from one point to another until the shape is drawn.

I wanted to know what is the best way for the program to create these points so that they appear on screen for the user to interact with them?

I have a canvas and the mouse is able to draw on the screen the problem is I don't know how to make the points interact-able with the mouse, so that when the mouse draws on or over the dots that it connects them together to form the letter.

\$\endgroup\$
2
  • \$\begingroup\$ Anything is possible; the only limitation is your own knowledge. \$\endgroup\$
    – Krythic
    Commented Nov 4, 2016 at 12:45
  • \$\begingroup\$ It's an underspecified problem: Let's say I start at the lower left dot. Let's say I draw a line to Timbuktu and back... and then move up to the next dot above it. Does this count as a valid line drawn? Exactly what do you consider "valid"? Squiggles? Curves with some maximum degree of variation? The easiest way I could see to deal with that, is to place an oval between any two points that should be connected; and the moment a pixel is drawn outside of that, you show a red X and force them to start that line segment over again. Still doesn't stop them making crazy shapes within that area! \$\endgroup\$
    – Engineer
    Commented Nov 4, 2016 at 13:16

1 Answer 1

1
\$\begingroup\$

Following answer is not targeting Java/Swing especially, it a general process.

  1. Best way to create the points :

I would personnaly use an array of points for each letter, the points having as coordinates the local position starting at the top-left of the letter. You can then draw a whole word by defining the global position of each letter.

  1. How to make the mouse interact with the points :

You should register whenever the user presses the mouse, get the x and y coordinates of the mouse click, and check if this point is inside one of your dots.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .