jeudi 3 mars 2016

calling IBAction button inside IBAction?

I got this IBAction that shuffles a pack of cards randomly

@IBAction func playRoundTapped(sender: UIButton) {

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



    let firstCardString:String = self.cardNamesArray[0]
    self.FirstCardImageView.image = UIImage(named: firstCardString)

    let SecondCardString:String = self.cardNamesArray2[1]
    self.SecondCardImageView.image = UIImage(named: SecondCardString)
    }

...and this part of the code scores a point when the cards match, however when they macth I need to it to shuffle again. Can I use IBAction playRoundTapped inside IBAction snapButtonTapped?

@IBAction func SnapButtonTapped(sender: UIButton) {


        if firstRandomNumber == SecondRandomNumber {

        print("index match")

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

        cardNamesArray.removeAtIndex(firstRandomNumber)
        cardNamesArray2.removeAtIndex(SecondRandomNumber)

            if cardNamesArray.count == 0 && cardNamesArray2.count == 0{


                print("user won")
                //alert box
                let alert = UIAlertController(title:"Level completed", message: "Your score is \(playerScore)", preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title:"next level", style: UIAlertActionStyle.Default, handler: nil))
                    self.presentViewController(alert, animated:true, completion:nil)

            }

    }




Aucun commentaire:

Enregistrer un commentaire