Time for action - build the deck

The strategy we'll use to build our deck is to create an array of possibilities, randomly choose one of those possibilities, and then remove that possibility as an option. Let's see how that works.

  1. In the BuildDeck function, start off by declaring a few variables:
    function BuildDeck()
    {
    var totalRobots:int = 4; // we've got four robots to work with
    var card:Object; // this stores a reference to a card
    }
    
  2. Next, build a loop to step through each of the four colored robot types:
    for(i=0; i<totalRobots; i++)
    {
    }
    

    That loop will run four times because totalRobots is set to 4. Next, create an array called RobotParts that will house the names of the body parts we can knock off:

    for(i=0; i<totalRobots; i++) { var aRobotParts:Array ...

Get Unity 3D Game Development by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.