Pumpkin eater
If you hail from Cheaty-Pants land, you may have figured out that you can flip over the same card twice. This isn't technically cheating, but when you break the game, you're only cheating yourself. We also have to be careful because a click-happy player might accidentally double-click the first card, and then think that the game is broken when he can't flip over a second card. Let's wrap the FlipCardFaceUp
in a conditional statement to prevent this from happening:
function FlipCardFaceUp(card:Card) { card.isFaceUp = true; if(aCardsFlipped.IndexOf(card) < 0) { aCardsFlipped.Add(card); // (the rest of the code is omitted) } }
What just happened?
This is where we finally get some mileage out of our Generic List
class. Generic List
has a method called IndexOf
that searches itself for an element, and returns the index point of that element.
Take a look at this example (the log's "answers" are commented at the end of each line):
var aShoppingList: List...