我是编程新手!不要介意AS3,并且在尝试将特定数量的Clicks设置为MovieClip数组时会遇到问题。这可能听起来不太正确,所以我会让你知道我正在做什么。
我目前正在尝试创建一个Battleships类型的游戏,并为玩家网格和计算机/ AI网格设置和网格阵列。当我点击播放器网格中的一个网格图块时,我正在更改MovieClip框架以显示不同的图形(代表该船的不同图块)。这一切都运行正常,但我想限制玩家只能点击15次,但现在玩家可以点击任意次数。
任何帮助都会受到高度赞赏,以及任何指导(正如我所说,我对这一切都很陌生)。
这是我到目前为止所做的:
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));
}
答案 0 :(得分:1)
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));
}