Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

GameEngine.swift

Blame
  • GameEngine.swift 4.59 KiB
    //
    //  GameEngine.swift
    //  Pendu
    //
    //  Created by Sofiane Lasri-Trienpont on 09/05/2023.
    //
    
    import UIKit
    
    class GameEngine: NSObject {
    
        private var listThemeAnimalsEasy : [String] = ["Chien", "Chat", "Lion", "Girafe", "Éléphant", "Serpent", "Oiseau", "Tigre", "Papillon", "Singe"]
        private var listThemeSportsEasy : [String] = ["Football", "Basket-ball", "Tennis", "Natation", "Rugby", "Golf", "Volley-ball", "Baseball", "Athlétisme", "Boxe"]
        private var listThemeFoodEasy : [String] = ["Pomme", "Banane", "Carotte", "Poisson", "Riz", "Fromage", "Pain", "Chocolat", "Fraise", "Poulet"]
        private var listThemeCitiesEasy : [String] = ["Paris", "Londres", "New York", "Rome", "Tokyo", "Sydney", "Barcelone", "Berlin", "Istanbul", "Mumbai"]
        private var listThemeColorsEasy : [String] = ["Rouge", "Bleu", "Vert", "Jaune", "Rose", "Violet", "Orange", "Gris", "Marron", "Noir"]
    
        private var listThemeAnimalsHard : [String] = ["Chimpanzé", "Lynx", "Hippopotame", "Pélican", "Kangourou", "Anaconda", "Chimère", "Panda roux", "Calmar géant", "Ouistiti"]
        private var listThemeSportsHard : [String] = ["Escrime", "Squash", "Haltérophilie", "Badminton", "Ski de fond", "Pentathlon moderne", "Canoë-kayak", "Aviron", "Patinage artistique", "Triathlon"]
        private var listThemeFoodHard : [String] = ["Artichaut", "Quinoa", "Courge", "Wasabi", "Chou-fleur", "Sarrasin", "Salsifis", "Morue", "Canneberge", "Pistache"]
        private var listThemeCitiesHard : [String] = ["Copenhague", "Budapest", "Dubrovnik", "Séoul", "Marrakech", "Reykjavik", "La Nouvelle-Orléans", "Bratislava", "Wellington", "Accra"]
        private var listThemeColorsHard : [String] = ["Écarlate", "Azur", "Émeraude", "Safran", "Pourpre", "Indigo", "Sienne", "Cyan", "Vermillon", "Lavande"]
        
        private var wordToGuess : String = ""
        private var attemptsRemaining : Int = 0
        private var guessedLetters : [Character] = []
     
        override init() {
            //
        }
        
        func WordToGuess(theme: String, difficulty: String) -> String{
            var word = ""
            if theme == "Animals"{
                if difficulty == "Easy"{
                    let randomInt = Int.random(in: 0..<listThemeAnimalsEasy.count)
                    word = listThemeAnimalsEasy[randomInt]
                } else {
                    let randomInt = Int.random(in: 0..<listThemeAnimalsHard.count)
                    word = listThemeAnimalsHard[randomInt]
                }
            } else if theme == "Sports"{
                if difficulty == "Easy"{
                    let randomInt = Int.random(in: 0..<listThemeSportsEasy.count)
                    word = listThemeAnimalsEasy[randomInt]
                } else {
                    let randomInt = Int.random(in: 0..<listThemeSportsHard.count)
                    word = listThemeSportsHard[randomInt]
                }
            } else if theme == "Food"{
                if difficulty == "Easy"{
                    let randomInt = Int.random(in: 0..<listThemeFoodEasy.count)
                    word = listThemeFoodEasy[randomInt]
                } else {
                    let randomInt = Int.random(in: 0..<listThemeFoodHard.count)
                    word = listThemeFoodHard[randomInt]
                }
            } else if theme == "Cities"{
                if difficulty == "Easy"{
                    let randomInt = Int.random(in: 0..<listThemeCitiesEasy.count)
                    word = listThemeCitiesEasy[randomInt]
                } else {
                    let randomInt = Int.random(in: 0..<listThemeCitiesHard.count)
                    word = listThemeCitiesHard[randomInt]
                }
            } else if theme == "Colors"{
                if difficulty == "Easy"{
                    let randomInt = Int.random(in: 0..<listThemeColorsEasy.count)
                    word = listThemeColorsEasy[randomInt]
                } else {
                    let randomInt = Int.random(in: 0..<listThemeColorsHard.count)
                    word = listThemeColorsHard[randomInt]
                }
            }
            return word
        }
        
        public func startNewGame(difficulty: String) -> Void {
            print(WordToGuess(theme: "Animals", difficulty: "Easy"))
        }
        
        public func guessLetter(letter: Character) -> Void {
            // Vérification de la lettre proposée par le joueur
            // Mise à jour de l'état de la lettre
        }
        
        public func isGameOver() -> Bool {
            // Vérification si le jeu est terminé
            return false;
        }
        
        public func isLetterGuesses(letter: Character) -> Bool {
            return false;
        }
        
        public func saveScore() -> Void {
            // Enregistrement du score dans la base Core Data
        }
        
        static func getOnlineScoreboard() -> Void {
            // Récupération du classement depuis le serveur
        }
    }