Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip; // import statements
- import flash.events.Event;
- import flash.events.MouseEvent;
- public class drawClass extends MovieClip
- {
- var i:int;
- var rand:int;
- var k:int;
- //instance variables go here!
- var playerHand:Array = new Array(); // this is the player hand array
- var currentDeck:Array = new Array("Dragon", "Squirrel", "Turtle", "Bat", "Hedgehog"); // this is be the current deck. Draw cards from here.
- //var temp:Array = new Array(); // a temporary array in order to store cards to be drawn into the hand
- // constructor function (must be named as the .as file is)
- public function drawClass()
- {
- var DrawButton:MovieClip = new drawButton();
- addChild(DrawButton);
- DrawButton.x = 500;
- DrawButton.y = 330;
- //clickable button
- DrawButton.addEventListener(MouseEvent.MOUSE_DOWN, cardPickUp); // click on the button then run the function "cardPickUp"
- }
- // other functions can go here.
- public function cardPickUp(e:Event = null):void
- {
- // draw a card
- //playerHand.push("Dragon");
- trace("A Card has been Drawn!");
- // the randomising loop.
- for(i = 0; i < currentHand.length; i++)
- {
- trace("loop begins");
- if(currentDeck.length == 0) break;
- rand = Math.floor(currentDeck.length * Math.random());
- playerHand.push(currentDeck.splice(rand,1)[0]);
- //show that the card has been picked up
- trace(playerHand);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment