|
-
[RESOLVED] Help make board game
Hi I'm trying to recreate a board game and want to know how to get the pieces to be removed if surrounded on 4 sides.
function onClick(e:MouseEvent):void
{
if (counterBlack == counterWhite)
{
var black:stoneBlack = new stoneBlack();
//other code for sizing positioning etc.
addChild(black);
counterBlack++;
}
else
{
var white:stoneWhite = new stoneWhite();
//other code for sizing positioning etc.
addChild(white);
counterWhite++;
}
}
the stoneWhite and stoneBlack classes are empty classes. the counterBlack and counterWhite determine which person's turn it is
-
Pumpkin Carving 2008
There just isn't enough information to help explain how you do it. What do you mean on four sides? Is it a tile based board? What's in the surrounding sides, other pieces? You commented out positioning, but how does that work? You've got to give a little more code or a better explanation if you're looking for advice.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
I assume that you're using a 2 dimensional square board, like a chess board, and that you're wanting to remove a piece when it has a piece of the opposing colour on all 4 sides...
There are 2 things you need to check - firstly whether the piece is at the edge, or in the corner of the board. On the edge it will only have 3 liberties (i.e. max of 3 pieces next to it) while in the corner it can only have 2.
Check for these positions first, and deal with them as a special case of the main check...
Assuming that the piece is on a "normal" square... you'll want to check each of the 4 surrounding squares in turn and see if an opposing piece is there.
Set a variable to true (i.e. captured=true then check each square in turn, if it is empty or of the same colour set captured to false, and exit the loop.
If it is an opposing colour keep captured set to true and move on to the next square. After checking all 4 squares, if captured is set to true remove the piece!
As for the exact code for checking each square that will depend in how you're storing your game positions. If you're using a 2 dimensional array it's quite simple to check, just be careful at the edges of the board where your math will be a little different!
Hope that helps,
Billy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|