jeudi 3 mars 2016

arrays not matching to the same element

I'm trying to Shuffle an array with GameplayKit and match them to the correct card. The shuffling part works but it doesn't match to the correct array.

var cardNamesArray: [String] = ["acorn", "angry","apple", "rainbow", "sad","boots", "heart", "pumpkin","chestnuts"]

var cardNamesArray2: [String] = ["bellota", "enfadado","manzana", "arcoiris","triste","botas","corazon", "calabaza", "castana"] 

cards are shuffled

@IBAction func playRoundTapped(sender: UIButton) {


    cardNamesArray = GKRandomSource.sharedRandom().arrayByShufflingObjectsInArray(cardNamesArray) as! [String]
    cardNamesArray2 = GKRandomSource.sharedRandom().arrayByShufflingObjectsInArray(cardNamesArray2) as! [String]

    print(cardNamesArray[0])
    print(cardNamesArray2[0])

    //firstRandomNumber = Int (arc4random_uniform(UInt32(cardNamesArray.count)))
    //secondRandomNumber = Int (arc4random_uniform(UInt32(cardNamesArray.count)))

    FirstCardImageView.image = UIImage(named: cardNamesArray[0])
    SecondCardImageView.image = UIImage(named: cardNamesArray2[0])       

}

cards still match when they are odd should match only even cards but not sure why is not working.

@IBAction func SnapButtonTapped(sender: UIButton) {



        if firstRandomNumber == secondRandomNumber {

           //self.playRoundTapped(self.PlayRoundButton) 

        print("index match")

        self.playerScore += 1
        self.playerScoreLabel.text = String(self.playerScore)

            cardNamesArray.removeAtIndex(firstRandomNumber)
            cardNamesArray2.removeAtIndex(secondRandomNumber)

    }

  }

}




Aucun commentaire:

Enregistrer un commentaire