So I am creating a card game, Ring of Fire. I have stored images like this:
var picture:[UIImage] = [
UIImage(named: "Card2")!,
UIImage(named: "Card3")!,
UIImage(named: "Card4")!,
UIImage(named: "Card5")!,
UIImage(named: "Card6")!,
UIImage(named: "Card7")!,
UIImage(named: "Card8")!,
UIImage(named: "Card9")!,
UIImage(named: "Card10")!,
UIImage(named: "CardJack")!,
UIImage(named: "CardQueen")!,
UIImage(named: "CardKing")!,
UIImage(named: "CardAce")!,
]
Each card has text displayed under the current card:
var name:String = ""
var files = ["Velg en som må drikke", // 2
"Drikk selv", // 3
"Alle jenter må drikke", // 4
"Tommelen", // 5
"Alle gutter må drikke", // 6
"Pek på himmelen", // 7
"Drikkepartner", // 8
"Rim", // 9
"Kategori", // 10
"Lag en regel", // Jack
"Spørsmålsrunde", // Queen
"Hell drikke i koppen", // King
"Fossefall"] // Ace
And this is how I pick a random card:
func imageTapped(img: AnyObject){
if(cardsleftLabel.text != "0") {
let randomNumber = Int(arc4random_uniform(UInt32(files.count)))
let image = picture[randomNumber]
cardImage.image = image
name = files[randomNumber]
}
else{
print("No more cards")
}
}
The problem is that the card may appear many times, and that is wrong. There are 4 of each card, so how can I control that in my game? So the CardJack don't appear 6 times?
Aucun commentaire:
Enregistrer un commentaire