i want to access all the elements of my dictonary without repeating them randomly. here is my code
var aleatorios = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52]
var check = [Int]()
var cartas = ["1": "cartas/1.png","2": "cartas/2.png","3": "cartas/3.png","4": "cartas/4.png","5": "cartas/5.png","6": "cartas/6.png","7": "cartas/7.png","8": "cartas/8.png","9": "cartas/9.png","10": "cartas/10.png","11": "cartas/11.png","12": "cartas/12-corazones.png","13": "cartas/13-corazon.png","14": "cartas/14.png","15": "cartas/15.png","16": "cartas/16.png","17": "cartas/17.png","18": "cartas/18.png","19": "cartas/19.png","20": "cartas/20.png","21": "cartas/21.png","22": "cartas/22.png","23": "cartas/23.png","24": "cartas/24.png","25": "cartas/25.png","26": "cartas/26.png","27": "cartas/27.png","28": "cartas/28.png","29": "cartas/29.png","30": "cartas/30.png","31": "cartas/31.png","32": "cartas/32.png","33": "cartas/33.png","34": "cartas/34.png","35": "cartas/35.png","36": "cartas/36.png","37": "cartas/37.png","38": "cartas/38.png","39": "cartas/39.png","40": "cartas/40.png","41": "cartas/41.png","42": "cartas/42.png","43": "cartas/43.png","44": "cartas/44.png","45": "cartas/45.png","46": "cartas/46.png","47": "cartas/47.png","48": "cartas/48.png","49": "cartas/49.png","50": "cartas/50.png","51": "cartas/51.png","52": "cartas.52.png"]
@IBAction func jugarcarta(_ sender: Any) {
let tamano = aleatorios.count
var random = Int(arc4random_uniform(UInt32(tamano))) + 1
print (random)
print (cartas["\(random)"]!)
let index = aleatorios.index(of: random)
print (index!)
print ("index")
if aleatorios.contains(random) {
carta.image = UIImage(named: cartas["\(random)"]!)
aleatorios.remove(at: index!)
} else {
random = Int(arc4random_uniform(UInt32(tamano))) + 1
}
Aucun commentaire:
Enregistrer un commentaire