私は単純な集中ゲームの5x4タイルを持っています(11フレームの1つのシンボル(tile_movieclip)があります-10フレームの番号は1-10で11番目の背景(シャツカード)です)。
最初は数字が表示され、数秒後にタイルが背景(11番目のフレーム)に変わる必要があります。私のコードでは、最初はすべての数字が表示され、1秒間は1つ(右下隅)のタイルだけが回転します。助けてください。
PS検索//エラーはここにあります!!!!! -そこに問題が隠れていると思いますが、よくわかりません。
ここにソースがあります:
package {
// importing classes
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
// end of importing classes
public class Main extends Sprite {
private var pickedTiles:Array = new Array();
private const NUMBER_OF_TILES:uint=20;
private var pause_game:Timer;
private var canPick:Boolean=true;
private var tiles:Array = new Array();
private var tile:tile_movieclip;
private var i:uint = 0;
public function Main() {
// variables and constants
// no more NUMBER_OF_TILES here
const TILES_PER_ROW:uint=5;
// end of variables and constants
// tiles creation loop
for (i=0; i<NUMBER_OF_TILES; i++) {
tiles.push(Math.floor(i/2));
}
trace("My tiles: "+tiles);
// end of tiles creation loop
// shuffling loop
var swap,tmp:uint;
for (i=NUMBER_OF_TILES-1; i>0; i--) {
swap=Math.floor(Math.random()*i);
tmp=tiles[i];
tiles[i]=tiles[swap];
tiles[swap]=tmp;
}
trace("My shuffled tiles: "+tiles);
// end of shuffling loop
// tile placing loop
for (i=0; i<NUMBER_OF_TILES; i++) {
tile=new tile_movieclip();
addChild(tile);
tile.cardType=tiles[i];
tile.x=5+(tile.width+5)*(i%TILES_PER_ROW);
tile.y=5+(tile.height+5)*(Math.floor(i/TILES_PER_ROW));
tile.gotoAndStop(tiles[i]+1); // This shows all number at first
canPick = false;
tile.buttonMode=true;
tile.addEventListener(MouseEvent.CLICK,onTileClicked);
}
pause_game=new Timer(1000,1);
pause_game.start();
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,hideTiles);
}
// end of tile_placing_loop
//Error can be HERE!!!!!
private function hideTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,hideTiles);
tile.gotoAndStop(NUMBER_OF_TILES/2+1); //This turns to background just one tile (the lower right corner)
canPick = true;
}
private function onTileClicked(e:MouseEvent) {
if(canPick){
var picked:tile_movieclip=e.currentTarget as tile_movieclip;
trace("you picked a "+e.currentTarget.cardType);
// checking if the current tile has already been picked
if (pickedTiles.indexOf(picked)==-1) {
pickedTiles.push(picked);
picked.gotoAndStop(picked.cardType+1);
}
// end checking if the current tile has already been picked
// checking if we picked 2 tiles
if (pickedTiles.length==2) {
canPick = false;
pause_game=new Timer(1000,1);
pause_game.start();
if (pickedTiles[0].cardType==pickedTiles[1].cardType) {
// tiles match!!
trace("tiles match!!!!");
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,removeTiles);
} else {
// tiles do not match
trace("tiles do not match");
pause_game.addEventListener(TimerEvent.TIMER_COMPLETE,resetTiles);
}
// no more pickedTiles = new Array();
}
// end checking if we picked 2 tiles
}
}
private function removeTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,removeTiles);
pickedTiles[0].removeEventListener(MouseEvent.CLICK,onTileClicked);
pickedTiles[1].removeEventListener(MouseEvent.CLICK,onTileClicked);
removeChild(pickedTiles[0]);
removeChild(pickedTiles[1]);
pickedTiles = new Array();
canPick = true;
}
private function resetTiles(e:TimerEvent) {
pause_game.removeEventListener(TimerEvent.TIMER_COMPLETE,resetTiles);
pickedTiles[0].gotoAndStop(NUMBER_OF_TILES/2+1);
pickedTiles[1].gotoAndStop(NUMBER_OF_TILES/2+1);
pickedTiles = new Array();
canPick = true;
}
}
}