actionscript3的小游戏开发模型

 

package com.playerlife.www

{

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import flash.text.TextField;

    

    public class Game extends Sprite

    {

        /**

         * 

         * @param event

         *状态循环........................ 

         */    

        private static const INIT_GAME:int = 100;

        private static const PLAY_GAME:int = 200;

        private static const GAME_OVER:int = 300;

        private var gameState:int = 0;

        private var clicks:int = 0;

        private var txt:TextField;

        

        public function Game()

        {

            init();

        }

        

        private function init():void

        {

            this.stage.addEventListener(Event.ENTER_FRAME, gameLoop);

            gameState = INIT_GAME;

            initShow();

        }

        

        private function initShow():void

        {

            txt = new TextField();

            txt.textColor = 0xff0000;

            addChild(txt);

            txt.x = 20;

            txt.y = 20;

        }

        

        /**

         * 

         * @param event

         *游戏频率........................ 

         */    

        private function gameLoop(event:Event):void

        {

            switch(gameState)

            {

                case INIT_GAME:

                    initGame();

                    break;

                case PLAY_GAME:

                    playGame();

                    break;

                case GAME_OVER:

                    gameOver();

                    break;

            }

        }

        

        private function initGame():void

        {

            this.stage.addEventListener(MouseEvent.CLICK, onClick);

            clicks = 0;

            txt.text = clicks.toString();

            gameState = PLAY_GAME;

        }

        

        private function playGame():void

        {

            txt.text = clicks.toString();

            if(clicks >= 10)

            {

                gameState = GAME_OVER;

            }

        }

        

        private function gameOver():void

        {

            this.stage.removeEventListener(MouseEvent.CLICK, onClick);

            gameState = INIT_GAME;

        }

        

        /**

         * 

         * @param event

         * 事件模型..................

         */        

        private function onClick(event:MouseEvent):void

        {

            clicks++;

        }

    }

}

 

 

 

 

 

你可能感兴趣的:(actionscript)