1
\$\begingroup\$

I have two images of the same dimensions. One is represents the game board in a user-appealing way, the other represents it in a computer-friendly way where each game area is painted in a unique, uniform color. When the user clicks the board, we get the click coordinates, find the color of the pixel at the same coordinates in our second image, and that color is directly translatable to a game area, since each area is painted in its own color.

Is that a good implementation? Can you suggest better, if it isn't?

Best regards.

\$\endgroup\$
  • \$\begingroup\$ Lacking further context or an actual problem to solve, I'd say "sounds great, go for it" \$\endgroup\$ – Hackworth Apr 14 '12 at 19:28
  • \$\begingroup\$ The problem to solve is maybe not stated in a very straightforward way in my post, I still hoped it was apparent. In a short way, what is a (the best?) way to know which area of a map was clicked from screen coordinates? Best regards. \$\endgroup\$ – pouzzler Apr 14 '12 at 20:00
0
\$\begingroup\$

Better to skip the image and just have a 2D array of pointers which indicate what game area it is. Since the second image is never displayed there's no reason for it to contain visible colours.

\$\endgroup\$
  • 3
    \$\begingroup\$ "Colors" is just a method to visualize the concept of a collection of identifiers. There is no difference between an array of int pointers and an array of int colors. The advantage of not using pointers is that you can choose a smaller data structure than int. If you have less than 256 areas, a byte will suffice, whereas a pointer is always an int. \$\endgroup\$ – Hackworth Apr 14 '12 at 22:23
  • \$\begingroup\$ A pointer is not always an int. The size of a pointer depends on your platform and whatever your compiler wants it to be (usually you, the user, decide this by targeting x86 or x64). Usually it will be 32 bit (which most of the time matches the size of an int) in 32 bit applications, and 64 bit in 64 bit applications. +1 on that comment though. \$\endgroup\$ – TravisG Apr 14 '12 at 22:44
  • \$\begingroup\$ You could just use an enum instead if you want. But my point stands- there's no reason to use a visible colour when it'll never be visible. \$\endgroup\$ – DeadMG Apr 15 '12 at 11:25
  • \$\begingroup\$ @DeadMG There seems to be a misunderstanding - The color map the OP proposes is not meant to be rendered, it's only for internally keeping track of areas, just like a pointer would. "Color" in this context is nothing but a mental help to understand the idea of an underlying data structure that the computer understands more easily than a nice map for humans. There are no actual colors being rendered to screen. \$\endgroup\$ – Hackworth Apr 15 '12 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.