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.

  1. 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
        }
  2. 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 to 4. Next, create a Generic List of type string called aRobotParts that will ...

Get Unity 4.x Game Development by Example Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.