Time for action – preparing to build the deck
Let's set up a deck-building function called BuildDeck
.
In the GameScript, create a new function called
BuildDeck
. Write this function outside of and apart from your other functions—make sure it's not trapped inside the curly brackets of one of your other functions.function BuildDeck() { }
Call the
BuildDeck
function in theStart
function, just after you define the three card-related collections:function Start() { playerCanClick = true; // We should let the player play, don't you think? // Initialize some empty Collections: aCards = new List.<Card>(); // this Generic List is our deck of cards. It can only ever hold instances ofthe Card class. aGrid = new Card[rows,cols]; // The rows and colsvariables help us define the dimensions of this 2Darray aCardsFlipped = new List.<Card>(); // This List willstore the two cards the player flips over. BuildDeck(); ...