模拟掷骰子 Simulating Dice

var  _die:Sprite;
  var _value:uint;
  public function flashtest()
  {
   _die = new Sprite();
   addChild(_die);
   _die.addEventListener(MouseEvent.CLICK,rollDie);
   rollDie(null); 
  }
  
  private function rollDie(event:MouseEvent):void
  {
   _value = NumberUtilities.random(1,6);
   _die.graphics.clear();
   _die.graphics.lineStyle();
   _die.graphics.beginFill(0xffffff);
   _die.graphics.drawRect(0,0,50,50);
   _die.graphics.endFill();
   _die.graphics.beginFill(0x000000);
   if(_value == 1 || _value == 3 || _value == 5)
   {
    _die.graphics.drawCircle(25,25,4);
   }
   if(_value == 2 || _value == 3 || _value == 4 || _value == 5 || _value == 6)
   {
    _die.graphics.drawCircle(11,11,4);
    _die.graphics.drawCircle(39,39,4);
   }
   if(_value == 4 || _value == 5 || _value == 6)
   {
    _die.graphics.drawCircle(11,39,4);
    _die.graphics.drawCircle(39,11,4);
   }
   if(_value == 6)
   {
    _die.graphics.drawCircle(11,25,4);
    _die.graphics.drawCircle(39,25,4);
   }
   
  }
posted @ 2011-03-10 15:36  Lester Programming  Views(295)  Comments(0Edit  收藏  举报