我在记分板上做错了什么

时间:2013-04-24 01:52:58

标签: actionscript-3

嗨,我是一个非常初学者,所以这对某些人来说似乎很愚蠢,但我正在敲打我的答案。我为匹配的游戏做了一个简单的记分牌。您的分数为50,并且每次选错都会丢失分数。但是我的得分总是保持在50分。感谢您的帮助。

package 
{
//importing classes
import flash.display.*;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.*;
import flash.text.TextField;


//end of importing classes
public class Main extends Sprite
{
private var pickedTiles:Array = new Array();
private const NUMBER_OF_TILES:uint=20;
private var pauseGame:Timer;
private var canPick:Boolean=true;
public var score:int;
public var scoreTextField:TextField;
public static var win: int;
public static var score: int;
{

    public function Main()
    {
        trace("Welcome to Aaron Collins' Beard Concentration");
        //variable and constants
        const NUMBER_OF_TILES:uint=20;
        var tiles:Array=new Array();

        const TILES_PER_ROW: uint=5;


        var tile: tile_movieclip;
        //end of variable and constants

        //tiles creation loop
        for (var i: uint=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);

        win = 0;
        score = 50;
        traceScore();

        //end of shuffling loop

        //tile placing loop
        for (var i:uint=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(NUMBER_OF_TILES+1);
                 tile.buttonMode = true;
            tile.addEventListener(MouseEvent.CLICK,onTileClicked); 
             }
             //end of placing loop
    }
    private function onTileClicked(e:MouseEvent)
    {
        if(canPick)

        {
        var picked:tile_movieclip=e.currentTarget as tile_movieclip;
            trace ("you picked a "+e.currentTarget.cardType);

        //Checking to see if the current tile has already been picked
            if (pickedTiles.indexOf(picked)==-1)
            {
                pickedTiles.push(picked);
                picked.gotoAndStop(picked.cardType+1);
            }
            //end checking if current tile has already been picked
            //checking if we picked two tiles

            if(pickedTiles.length==2)
            {
                canPick=false;
                pauseGame=new Timer(1000,1);
                pauseGame.start();
                if (pickedTiles[0].cardType==pickedTiles[1].cardType)
                    {
                        //tiles match
                        trace ("tiles match!!")

                        gameOver();

                        getPoints();

                        traceScore();

                            pauseGame.addEventListener(TimerEvent.TIMER_COMPLETE,removeTiles);

                           //pickedTiles[0].removeEventListener(MouseEvent.CLICK, onTileClicked);
                        //pickedTiles[1].removeEventListener(MouseEvent.CLICK, onTileClicked);
                        //removeChild(pickedTiles[0]);
                        //removeChild(pickedTiles[1]);

                    }
                    else
                    {
                        //tiles do not match
                        trace ("tiles do not match")

                        gameOver();

                        losePoints();

                        traceScore();

                        pauseGame.addEventListener(TimerEvent.TIMER_COMPLETE,resetTiles);

                        //pickedTiles[0].gotoAndStop(NUMBER_OF_TILES/2+1);
                        //pickedTiles[1].gotoAndStop(NUMBER_OF_TILES/2+1);

                    }
                    //pickedTiles = new Array();
                    //end checking if we picked 2 tiles
                }
        }
            }

            private function resetTiles(e:TimerEvent)
        {
            pauseGame.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;

        }
            private function removeTiles(e:TimerEvent)
        {
            pauseGame.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;
        }

            public function getPoints()
        {
            score + 5;
            win + 1;
        }

            public function losePoints()
        {
            score - 5;
        }

            public static function traceScore()
        {
            trace("Your Score Is " + score + "");
        }


            public function gameOver()
        {
                if (score == 0)
            {
                MovieClip(root).gotoAndStop("GameOver")
            }
                if (win == 10)
            {
                MovieClip(root).gotoAndStop("YouWin")
            }
        }



}
}

}

1 个答案:

答案 0 :(得分:3)

这是因为您没有更新代码中的分数变量,请查看以下方法:

    public function getPoints() {
        score + 5;
        win + 1;
    }

    public function losePoints() {
        score - 5;
    }

他们应该如下:

    public function getPoints() {
        score += 5;
        win += 1;
    }

    public function losePoints() {
        score -= 5;
    }