3

我是编程新手!不要介意 AS3 并且在尝试将特定数量的点击设置为一组 MovieClips 时会遇到问题。这听起来可能不正确,所以我会让你确切地知道我想要做什么。

我目前正在尝试创建一个战舰类型的游戏,并为玩家网格和计算机/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));
     }
4

1 回答 1

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));
 }
于 2012-11-09T16:13:29.360 回答