Skip to content
Snippets Groups Projects
Select Git revision
  • 3328020ff63b5de889d691e9bd6f149141fa12ea
  • main default protected
2 results

ViewController.swift

Blame
  • user avatar
    Nathan authored
    3328020f
    History
    ViewController.swift 2.29 KiB
    import UIKit
    
    class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
    
        @IBOutlet weak var classement: UIButton!
        @IBOutlet weak var pseudoinput: UITextField!
        @IBOutlet weak var choixTheme: UIPickerView!
        @IBOutlet weak var choixNiv: UISegmentedControl!
        
        var wordToGuess : String = ""
        let pickerData = ["Animals", "Sports", "Food", "Cities", "Colors"]
        var gameEngine : GameEngine = GameEngine()
        
        override func viewDidLoad() {
            super.viewDidLoad()
            choixTheme.dataSource = self
            choixTheme.delegate = self
        }
        
        override func prepare(for segue: UIStoryboardSegue, sender: Any?){
            if segue.identifier == "DeAccueilAJeu" {
                let destinationVC = segue.destination as! GameViewController
                destinationVC.gameEngine = gameEngine
                
            }
        }
        
        @IBAction func LancerPartie(_ sender: Any) {
            guard let pseudo = pseudoinput.text else {
                return
            }
            
            let niveauIndex = choixNiv.selectedSegmentIndex
            let niveau = choixNiv.titleForSegment(at: niveauIndex)
            
            let themeIndex = choixTheme.selectedRow(inComponent: 0)
            let theme = pickerData[themeIndex]
            
            // Utilisez les valeurs récupérées comme vous le souhaitez
            print("Pseudo: \(pseudo)")
            print("Niveau: \(niveau ?? "")")
            print("Thème: \(theme)")
            
            // Ajoutez votre code supplémentaire ici
            let difficulty = niveau ?? ""
    
            gameEngine.WordToGuess(theme: theme, difficulty: difficulty)
            print("Mot à deviner: \(wordToGuess)")
        }
        
        // MARK: - UIPickerViewDataSource
        
        func numberOfComponents(in pickerView: UIPickerView) -> Int {
            return 1
        }
        
        func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
            return pickerData.count
        }
        
        // MARK: - UIPickerViewDelegate
        
        func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
            return pickerData[row]
        }
        
        func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
            // Code à exécuter lorsque l'utilisateur sélectionne une valeur dans le pickerView.
        }
    }