• 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++;
            }
        }
    }
  • 相关阅读:
    中国式沟通
    10 表连接优化
    09 优化数据访问
    07 SQL优化技术
    06 执行计划
    04 系统和对象统计信息
    03 找出性能问题
    02 key concept
    Xpert 调优
    JavaWeb_常用功能_01_文件上传
  • 原文地址:https://www.cnblogs.com/playerlife/p/2727414.html
Copyright © 2020-2023  润新知