-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardSelectionVCViewController.swift
55 lines (39 loc) · 1.22 KB
/
CardSelectionVCViewController.swift
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
53
54
//
// CardSelectionVCViewController.swift
// cardgame
//
// Created by Abhishumat singh Beniwal on 14/12/23.
//
import UIKit
class CardSelectionVCViewController: UIViewController {
@IBOutlet var cardimageView: UIImageView!
@IBOutlet var buttons: [UIButton]!
var cards: [UIImage] = deck.allValues
var timer: Timer!
override func viewDidLoad() {
super.viewDidLoad()
startTimer()
for button in buttons{
button.layer.cornerRadius=8
}
}
override func viewWillDisappear( _ animated: Bool){
super.viewWillDisappear(animated)
timer.invalidate()
}
func startTimer(){
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(showRandomImage), userInfo: nil, repeats: true)
}
@objc func showRandomImage(){
cardimageView.image=cards.randomElement() ?? UIImage(named:"AH")
}
@IBAction func stoptapped(_ sender: UIButton) {
timer.invalidate()
}
@IBAction func rulestapped(_ sender: UIButton) {
}
@IBAction func restarttapped(_ sender: UIButton) {
timer.invalidate()
startTimer()
}
}