Time for action – building the deck
The strategy we'll use to build our deck is to create a list of possibilities, randomly choose one of those possibilities, and then remove that possibility as an option. Let's see how that works.
In the
BuildDeck
function, start off by declaring a few temporary variables:function BuildDeck() { var totalRobots:int = 4; // we've got four robots to work with var card:Card; // this stores a reference to a card }
Next, build a loop to step through each of the four colored robot types:
var card:Card; // this stores a reference to a card for(var i:int=0; i<totalRobots; i++) { }
That loop will run four times because
totalRobots
is set to4
. Next, create a Generic List of typestring
calledaRobotParts
that will house the names of the body parts we can knock off:for(i=0; i<totalRobots; i++) { var aRobotParts:List.<String> = new List.<String>(); aRobotParts.Add("Head"); aRobotParts...