Board game. page 2

Subscribe to Board game. 39 posts

avatar for gavisgone gavisgone 20 posts
Flag Post

Yeah I totally agree. Not looking for anything fancy, just a simple colour change so the player can see where their counter is going to be placed. I’m happy enough if the player counter is merely a different coloured square.
It’s crazy I’ve been trying to get onto actually getting the program to work but I’ve only just managed to place a 2d array of tiles on the stage that I can actually use!
Where do I use e.currentTarget so the event handlers work on every square on the grid?

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

replace squareMC with Evt.currentTarget

 
avatar for gavisgone gavisgone 20 posts
Flag Post

Ah fantastic thanks. I have a home button which takes me to the first frame, (the main board is on the second frame) I want to remove the mainBoard array when I click on this button as the game grid is still on the screen when I go back to frame 1. I’ve tried mainBoard.splice(0); in the button function but it doesn’t do anything.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by gavisgone:

Ah fantastic thanks. I have a home button which takes me to the first frame, (the main board is on the second frame) I want to remove the mainBoard array when I click on this button as the game grid is still on the screen when I go back to frame 1. I’ve tried mainBoard.splice(0); in the button function but it doesn’t do anything.

Two things:

1) mainBoard.splice() is only going to get rid of the one row of the array. use mainBoard = new Array();

2) That doesn’t remove objects from the stage.

I lied, three things:

3) mainBoard.splice(0) (with one parameter, not two) removes zero objects from the array.

 
avatar for gavisgone gavisgone 20 posts
Flag Post

Ok so mainBoard = new Array(); clears the array. And then I want to remove the squareMCs from the arrays. removeChild(squareMC); only removes the last Movie clip in the array. How would I clear the lot?

 
avatar for gavisgone gavisgone 20 posts
Flag Post

How would I then swap to player 2 and place a differently coloured tile on the board, then swap back to player 1?

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

Removing all children:

while(numChildren > 0) {
removeChildAt(0_
}

Though you might want to not attach your objects to the stage root, or otherwise store the squares in an array (right now you’re storing information related to the squares, but not the squares themselves).

As for the colors, you need to have a variable indicating which player is active, and then based on that, use a different color transform.

 
avatar for gavisgone gavisgone 20 posts
Flag Post

That removing all children code makes my program crash for some reason.
Ah right so is that going to make it harder to complete the way it is now? It’s due tomorrow night so I just want to be able to hand in a 2 player that works.

Would the player variable be another integer such as 3? Or is it done with a boolean value? Clearly I’m not getting my head around this yet but I need to start making some fast progress before tomorrow.

EDIT If I change the code to removeChildAt(1) it removes the grid from the screen. But it says RangeError: Error #2006: The supplied index is out of bounds. in the output. Apart from that seems to work fine.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by gavisgone:

That removing all children code makes my program crash for some reason.
Ah right so is that going to make it harder to complete the way it is now? It’s due tomorrow night so I just want to be able to hand in a 2 player that works.

Would the player variable be another integer such as 3? Or is it done with a boolean value? Clearly I’m not getting my head around this yet but I need to start making some fast progress before tomorrow.

EDIT If I change the code to removeChildAt(1) it removes the grid from the screen. But it says RangeError: Error #2006: The supplied index is out of bounds. in the output. Apart from that seems to work fine.

Then you also need to change numChildren > 1, also.

 
avatar for gavisgone gavisgone 20 posts
Flag Post

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. Could anyone show me how to do this please?

 
avatar for Ace_Blue Ace_Blue 1091 posts
Flag Post

It’s going to be slightly more complicated than that. when a player places a tile, you have to check along the eight surrounding directions (up-left, up, up-right, right, etc…).

Along each direction:
- initialize a counter at 0.
- Check the next square in that direction
- If it belongs to the current player, increment the counter, otherwise exit.
(optional) - if your counter is valued at 4 or more, exit.

Initialize a winning boolean to false.
Now add the counters for top-left and bottom-right. If they total 4 or more, set the winning boolean to true.
Repeat the process for the left and right counters.
Repeat for the up and down counters.
repeat for the bottom-left and top-right counters.

If the winning boolean is true, the current player has won, otherwise let the other player have a turn.

You still haven’t said why you’re tackling a project such as this when your programming skills are so rudimentary that you’ve had kind users on at least two different forums write pretty much all the code for you so far. Do you intend to pass the finished program as your own production?

 
avatar for gavisgone gavisgone 20 posts
Flag Post

Thanks I appreciate all of the help and time put in by other users to help me with this project. I was given the task to create a flash game of my choosing around a month ago and chose this board game. I had other projects in vb.net, HTML and DVD production to complete at the same time as well as exams to study for. In the class we were learning techniques for creating shoot em up games and principles of gravity in flash etc. Nothing really to do with this project. I didn’t realise how complicated this would be until I started really tackling the code around 10 days ago.
I appreciate that a lot of the code has been given to me by helpful users such as yourself, but not all of it and I will be referencing where I got help from in my evaluation report which I will write upon completion.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by gavisgone:

I was given the task to create a flash game of my choosing around a month ago and chose this board game.

Generally speaking that means “something you have confidence of being able to pull off.”

 
avatar for gavisgone gavisgone 20 posts
Flag Post

Ha I’m getting ripped to shreds now. Yup I should have picked something simpler. I wasn’t aware how hard AS3 was to understand when I picked the game. It’s my first ever Flash module.