I don't know if anyone remembers the old game called Metasquares, but it involved placing dots onto a 2D coordinate plane, and if four dots were made into a square (even if they squares were rotated), then it would draw a line going from one dot to the other, making a square outline. It was very fun and took a lot of strategy.
My question is, what would the formula be for figuring out if 4 coordinates on a 2D plane form a square?
wher you have 4 small squares that are formed more or less like this:
----
12
34
----
Pseudo code:
-------------------------------------------------------------------
If square2.X = (Square1.X + Square1.Width) and
Square2.Y = Square1.Y and
square3.X = square1.X and
square3.Y = (square1.Y + square1.height) and
I should have attached this first to let you know what I'm trying to do.
The user will click an open spot to place a dot in it's place. If four of these dots form a square in any way, then points are awarded.. the bigger the square, the more points. The screenshot is just something I tossed together that I want the game to look like.
Make a "coordinatesystem", on the picture you got 6*6 possitions. You could number all the coordinate like this:
(11)(21)(31)(41)(51)(61)
(12)(22)(32)(42)
(13)(23)(33)(43)
(14)
(15)
(16)
and so one....
When I look at my numbers now, it looks more like a 6dimensional array...maybe that would be the was. That would make the loop a lot easyer.
So you could try this.
If you want to check for scares that are formed like this:
12
34
it would be something like this:
Get the "coordinates" to the last green-spot that was visible. If the coordinates vas (32). Then you would have to check in your array if (31)(41)(42) also is visible, or (42)(33)(43) or (22)(23)(33) or (31)(21)(22) are visible. This would actually not be that difficult at all. Make a 6dimensiolnal array of Booleans. And check if this playses in the array is true...
If you don't understand let me know, and I try to express myselv in an easyer way. Or if you have problems turning this in to reel code, just ask again...
The squares aren't all at 0 degrees. Look at the picture in my last post and you'll see that the square formed is rotated. I'm still working on this also, if I come up with a solution, I'll let you know.
When a player clicks at a point (x, y), check for all possible squares from that point. Start with (1,1), and go until (6,6).
A square is formed by two deltas, let's say A and B. Important: A or B can also be negative, or 0 (in case you would have a rectangular square). A and B cannot both be zero.
Starting with (1,1), then A will be x-1 and B will be y-1. To reach the next point of the square you should add B to the X-coordinate and subtract A from the Y-coordinate. (See image)
Of course this will fall outside the game area, so you know this won't be a valid square.
In certain cases you will achieve a valid square. In such a case you should check whether all points are occupied by one player.
I hope this will work. Just ask if you need more info, and/or if I've been too unclear.
Some remarks and ideas:
* I don't link any squares with lines. It shouldn't be too hard. Load linear shapes dynamically, and draw them from centerpoint to centerpoints of points forming a square.
* Maybe you should make the size of the grid dynamically.
* Maybe you should make it possible to remove (strategically) points (center point, corner points, etc), so there might be fun. It isn't necessary to restrict to square grids, imho.