Hey guys!
I’m new in coding and I was working on Blackjack game and got stuck with the methods. Can someone explain me how can I use two IBAAction functions together?
For example, when you press shuffle (first button it will give a cards, but then I also want another button which will to determine whether hit another card or hold.
Create your two buttons in interface builder (storyboard) and give each of them their own IBAction connection in your corresponding ViewController.swift file and then in each add the appropriate code so that when you tap on either button the code does what you expect.
Perhaps the solution is to set some Boolean values that you can interrogate. Try setting up one that stores hitTapped (or whatever you prefer to call it) and set that to true if the player has tapped the hit button otherwise set to false. When you define the Boolean at the top of your ViewController set it to false by default
var hitTapped = false
So in your shuffleTapped() button code (if that is what you called it)
func shuffleCards() {
if hitTapped == true { // alternatively this can be coded as if hitTapped {
cards.shuffle()
// Deal one card
} else {
cards.shuffle()
// whatever code is required
}
}