Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-07-2012, 12:41 AM   #1
Keys
Registered User
 
Join Date: May 2012
Posts: 3
Default [AS3] Gomoku (5 in a row) board game

Hey there. I've just started out making a board game in AS3. Its a 15x15 grid of squares. It's a two player game where each player takes their turn to place their counter on the board. The first player to manage to get 5 of their counter in a row (up-down,left-right or diagonally) wins the game.


I believe i need to use e.currentTarget to make the event handlers function on every square. Could someone tell me how to do this?
Thanks in advance.

Last edited by Keys; 05-11-2012 at 07:55 PM.
Keys is offline   Reply With Quote
Old 05-10-2012, 01:13 PM   #2
dialectric
Senior Member
 
dialectric's Avatar
 
Join Date: May 2006
Location: USA
Posts: 614
Default

Hi,

You are on the right track with the e.currentTarget. In your case, though, you would use Evt.currentTarget, as the event is defined as Evt rather than the commonly used 'e':

function clickSquare(Evt:MouseEvent):void {
var myColor:ColorTransform = (Evt.currentTarget).transform.colorTransform;
myColor.color = 0xFFF000;
(Evt.currentTarget).transform.colorTransform = myColor;
}

- dialectric
dialectric is offline   Reply With Quote
Old 05-10-2012, 06:48 PM   #3
Keys
Registered User
 
Join Date: May 2012
Posts: 3
Default

Right I’ve got it working now so that player one can click a tile to add their colour, then the other player clicks and adds their colour.

So I just need to do one more thing. Being able to check that the player has made a winning move. 5 of their tiles in a row in any direction.
I’m thinking I’ll need to find the neighbouring index in the array in every direction each time a piece is played, then if it contains another piece of the same colour, move in that direction and count how many places it has moved until it equals 5. Any idea how to do this?

Last edited by Keys; 05-11-2012 at 07:54 PM.
Keys is offline   Reply With Quote
Old 05-10-2012, 11:54 PM   #4
dialectric
Senior Member
 
dialectric's Avatar
 
Join Date: May 2006
Location: USA
Posts: 614
Default

Checking through 2d arrays with as3 is fast, so the most straightforward way to do this would be to check the entire array for chains.

Write a for loop that cycles through the entire array, and for each block, run a function that establishes temp_chain_length = 0, checks down, right, and diagonally down and right, then, if that returns true, temp_chain_length++, and repeat with the tile and direction that returned true. When you hit chain length of 5, game over.

-dialectric
dialectric is offline   Reply With Quote
Old 05-11-2012, 01:15 AM   #5
Keys
Registered User
 
Join Date: May 2012
Posts: 3
Default

Could you perhaps show me how the code might look for that? I can't quite get my head around it.

-thanks
Keys is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:11 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.