记忆游戏(flex3版)


记忆游戏(flex3版)
2010年12月12日
  接触flex其实非常偶然的,还没毕业前,压根都没想过自己会从事flex编程。可是事实就是这样的莫名奇妙,自己都还没搞清情况,就毫无征兆被一家开发网页游戏公司招了(前台flash).........哈哈,想起自己都还有点心虚。
  刚进公司时,对flex可是毫无了解,心里还真有点怕的,毕竟是第一次,而且还是从事一项不熟悉的语言开发。不过摸索了两三天,哈,其实对程序员来说任何的程序语言只是一个工具而已,有了编程基础想掌握另一项语言,其实很容易,所以两三天的时间,已经足够去掌握一项新的语言(当然只是了解的其中的用法哈)........废话不多说,下面就分享那段时间,练习时自己写的一个小游戏:
  //这个游戏很简单(效果图) 
  
  package com.indawn
  {
  import flash.display.Loader;
  import flash.events.MouseEvent;
  import flash.events.TimerEvent;
  import flash.net.URLRequest;
  import mx.containers.Box;
  import mx.containers.HBox;
  import mx.containers.VBox;
  import mx.core.Application;
  /**游戏功能的主要实现类**/
  public class GamePanel extends Box 
  {
  private var m:int = 0;
  private var n:int = 0;
  private var buttons:Array = new Array();
  private var tempGameButton:GameButton;
  private var openGameButton:Array = new Array();
  private var count:Number;
  private var gameStart:Boolean;
  public  function GamePanel(m:int,n:int)
  {
  super();
  this.m = m;
  this.n = n;
  initGamePanel()
  }
  /**游戏初始化数据**/
  private function initGamePanel():void
  {
  for(var i:int = 0;i游戏时,因确定有文件存在
  }  
  stopTime();
  setRandomIcon(buttons,icons);  
  }
  /**随机分布图标**/
  private function setRandomIcon(_bs:Array,icons:Array):void
  {
  for(var i:int=0;i0)
  {
  do
  {
  index = Math.round(Math.random()*icons.length); 
  }while(icons[index]==undefined)
  }else
  {
  index = 0;
  }  
  (_bs[i] as GameButton).buttonURL = icons[index];
  icons.splice(index,1);
  icons.sort(); 
  } 
  }
  /**监听点击按钮事件**/
  private function openButtonIcon(event:MouseEvent):void
  {
  var button:GameButton= (event.target as GameButton);
  gameStart  =  true;
  if(!button.buttonOPEN)
  {
  tempGameButton = button;
  var loader:Loader=new Loader();
  loader.load(new URLRequest(button.buttonURL));
  button.addChild(loader);
  loader.x   =  10 ;
  loader.y   =  2;
  button.enabled  = false;
  isGameOver();
  }
  } 
  /**判断游戏是否线束**/
  private function isGameOver():void
  {
  if(openGameButton.length>0)
  {
  if((openGameButton[0] as GameButton).buttonURL!=tempGameButton.buttonURL)
  {
  closeGameButton();   
  } 
  openGameButton.push(tempGameButton); 
  tempGameButton.buttonOPEN = true ; 
  if(openGameButton.length>=m)
  {
  setGameButtonEnableFalse();
  openGameButton.splice(0,openGameButton.length); 
  }                        
  }
  else
  {
  tempGameButton.buttonOPEN = true ;
  openGameButton.push(tempGameButton);             
  }
  }
  /**打开的图标和上次不同,将关闭打开 的所有图标**/
  private function closeGameButton():void
  {
  for(var i:int = 0; i游戏将按钮设置为不可点击**/
  private function setGameButtonEnableFalse():void
  {
  for(var i:int = 0; i0&&value
  
  
  
  
  -->
  游戏" backgroundColor="#752525" width="530" height="255" id="gamePanel"  focusColor="#1D5C97">
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
  
    
  
  
  //最后还要加入一些测试的swf文件,在flex的IDE项中的src下面加入名称(0.swf---7.swf)swf文件
  ================================================== ==========================================
  例子并不复杂,但很适合刚入门flex的朋友们了解as3.0,晒晒分享一下.........哈...
  (个人表达能力不好,所以对程序不做过多的说明,想了解的朋友自己去看看,以后有时间将继续分享以前学习自己写的小游戏,谢谢............)
  

猜你喜欢

转载自szas26szas.iteye.com/blog/1571776
今日推荐