Guest User

drawClass

a guest
Apr 23rd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.MovieClip; // import statements
  4.     import flash.events.Event;
  5.     import flash.events.MouseEvent;
  6.  
  7.     public class drawClass extends MovieClip
  8.     {
  9.         var i:int;
  10.         var rand:int;
  11.         var k:int;
  12.         //instance variables go here!
  13.         var playerHand:Array = new Array(); // this is the player hand array
  14.        
  15.         var currentDeck:Array = new Array("Dragon", "Squirrel", "Turtle", "Bat", "Hedgehog"); // this is be the current deck. Draw cards from here.
  16.        
  17.         //var temp:Array = new Array(); // a temporary array in order to store cards to be drawn into the hand
  18.        
  19.         // constructor function (must be named as the .as file is)
  20.         public function drawClass()
  21.         {
  22.            
  23.            
  24.             var DrawButton:MovieClip = new drawButton();
  25.             addChild(DrawButton);
  26.             DrawButton.x = 500;
  27.             DrawButton.y = 330;
  28.            
  29.             //clickable button
  30.             DrawButton.addEventListener(MouseEvent.MOUSE_DOWN, cardPickUp); // click on the button then run the function "cardPickUp"
  31.         }
  32.        
  33.        
  34.         // other functions can go here.
  35.        
  36.         public function cardPickUp(e:Event = null):void
  37.         {
  38.             // draw a card
  39.             //playerHand.push("Dragon");
  40.             trace("A Card has been Drawn!");
  41.                        
  42.             // the randomising loop.
  43.             for(i = 0; i < currentHand.length; i++)
  44.             {
  45.                 trace("loop begins");
  46.                
  47.                 if(currentDeck.length == 0) break;
  48.                
  49.                
  50.                
  51.                 rand = Math.floor(currentDeck.length * Math.random());
  52.                
  53.                
  54.                 playerHand.push(currentDeck.splice(rand,1)[0]);
  55.                
  56.                 //show that the card has been picked up
  57.                 trace(playerHand);
  58.             }
  59.            
  60.            
  61.         }
  62.        
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment