Time for action – modifying the img argument
Because we're passing a new argument to the Card
class, we have to modify the Card
class to accept it.
Change the
Card
class code from this:class Card extends System.Object { // (variables omitted for clarity) function Card() { img = "robot"; } }
to this:
class Card extends System.Object { // (variables omitted for clarity) function Card(img:String) { this.img = img; } }
Now, find the nested loop in the
Start
function where we added all our new cards to theaGrid
array. Change it from this:for(j=0; j<cols; j++) { aGrid[i,j] = new Card(); }
to this:
for(j=0; j<cols; j++) { var someNum:int = Random.Range(0,aCards.Count); aGrid[i,j] = aCards[someNum]; aCards.RemoveAt(someNum); }
What just happened?
This code should look familiar to you, because we're pulling a very similar trick as before. We have a deck of cards—the aCards
List. After the BuildDeck...