I'm new to Programming! Never mind AS3 and have problem when trying to set a specific number of Clicks to an Array of MovieClips. This might not sound correct so I will let you know exactly what I'm trying to do.
I'm currently trying to create a Battleships type game and have set-up and Array of Grid tiles for both the players grid and the computer/AI grid. When I click onto one of the grid tiles in the players grid I'm changing the MovieClip frame to display a different graphic (different tile that represents the ship). This is all working fine but I want to restrict the player to only being able to click 15 times but as it now stands the player can click as many times as they want.
Any help would be greatly appreciated, along with any guidance (as I said I'm really new to all this).
Here is what I have so far:
var i:int = 0;
var playerTileArray:Array = new Array();
var compTileArray:Array = new Array();
for (var v:uint = 0; v < 20;v++){
for (var h:uint = 0; h < 20;h++){
playerTileArray[i] = new gridTile(); //gridTile is a MovieClip symbol in my Library.
playerTileArray[i].x = h*20;
playerTileArray[i].y = v*20 + 50;
playerTileArray[i].addEventListener(MouseEvent.CLICK, playerClick);
this.addChild(playerTileArray[i]);
trace ("creating player vertical tile " + v);
trace ("creating player horizontal tile " + h);
compTileArray[i] = new gridTile(); //gridTile is a MovieClip symbol in my Library.
compTileArray[i].x = playerTileArray[i].x + 600;
compTileArray[i].y = playerTileArray[i].y;
this.addChild(compTileArray[i]);
trace ("creating computer vertical tile " + v);
trace ("creating computer horizontal tile " + h);
i++;
}
}
function playerClick(e:MouseEvent):void{
e.currentTarget.gotoAndStop(2);
trace("placed ship on player grid at: " + playerTileArray.indexOf(e.currentTarget));
}
var clickCount:int = 0;
function playerClick(e:MouseEvent):void{
if( clickCount >= 15 ){
return;
}
++clickCount
e.currentTarget.gotoAndStop(2);
trace("placed ship on player grid at: " + playerTileArray.indexOf(e.currentTarget));
}