Skip to content
Snippets Groups Projects
Commit 88d165c8 authored by Nathan's avatar Nathan
Browse files

remove word

parent 19823115
Branches
No related tags found
No related merge requests found
......@@ -11,15 +11,15 @@ import CoreData
class GameEngine: NSObject {
private var listThemeAnimalsEasy : [String] = ["Chien", "Chat", "Lion", "Girafe", "elephant", "Serpent", "Oiseau", "Tigre", "Papillon", "Singe"];
private var listThemeSportsEasy : [String] = ["Football", "Basket-ball", "Tennis", "Natation", "Rugby", "Golf", "Volley-ball", "Baseball", "Athletisme", "Boxe"];
private var listThemeSportsEasy : [String] = ["Football", "Tennis", "Natation", "Rugby", "Golf", "Baseball", "Athletisme", "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] = ["Chimpanze", "Lynx", "Hippopotame", "Pelican", "Kangourou", "Anaconda", "Chimere", "Panda roux", "Calmar geant", "Ouistiti"];
private var listThemeSportsHard : [String] = ["Escrime", "Squash", "Halterophilie", "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", "Seoul", "Marrakech", "Reykjavik", "La Nouvelle-Orleans", "Bratislava", "Wellington", "Accra"];
private var listThemeAnimalsHard : [String] = ["Chimpanze", "Lynx", "Hippopotame", "Pelican", "Kangourou", "Anaconda", "Chimere", "Panda roux", "Ouistiti"];
private var listThemeSportsHard : [String] = ["Escrime", "Squash", "Halterophilie", "Badminton", "Aviron", "Triathlon"];
private var listThemeFoodHard : [String] = ["Artichaut", "Quinoa", "Courge", "Wasabi", "Sarrasin", "Salsifis", "Morue", "Canneberge", "Pistache"];
private var listThemeCitiesHard : [String] = ["Copenhague", "Budapest", "Dubrovnik", "Seoul", "Marrakech", "Reykjavik", "Bratislava", "Wellington", "Accra"];
private var listThemeColorsHard : [String] = ["ecarlate", "Azur", "emeraude", "Safran", "Pourpre", "Indigo", "Sienne", "Cyan", "Vermillon", "Lavande"];
private var wordToGuess : String = "";
......@@ -166,6 +166,18 @@ class GameEngine: NSObject {
return self.score;
}
public func getPlayerName() -> String {
return self.playerName;
}
public func getDifficulty() -> String {
return self.difficulty;
}
public func getCategoryName() -> String {
return self.theme;
}
public func saveScore() -> Void {
// Enregistrement du score dans la base Core Data
......
......@@ -185,11 +185,16 @@ class GameViewController: UIViewController {
func initializeWordState() {
let words = wordToGuess.components(separatedBy: " ")
print(words)
for word in words {
var wordState = ""
for _ in word {
for char in word {
if char == " " {
wordState += " "
} else {
wordState += "_"
}
}
currentWordState.append(wordState)
}
}
......@@ -201,6 +206,26 @@ class GameViewController: UIViewController {
func checkIfWordFound() {
if currentWordState.joined() == wordToGuess {
let url = URL(string: "https://miscs.sl-projects.com/IUT-ORSAY/LP-PRISM/TP-iOS/")
let parametre = ["score": gameEngine.getScore(), "categoryName": gameEngine.getCategoryName(), "difficulty": gameEngine.getDifficulty(), "playerName": gameEngine.getPlayerName()] as [String : Any]
let jsonData = try? JSONSerialization.data(withJSONObject: parametre)
// Créer une requête URLRequest
var request = URLRequest(url: (url)!)
request.httpMethod = "POST"
request.httpBody = jsonData
// Créer une session URLSession
let session = URLSession.shared
// Créer une tâche de données pour envoyer la requête
let task = session.dataTask(with: request)
// Démarrer la tâche de données
task.resume()
isWordFound = true
wordLabel.textColor = UIColor.green
A_Button.isHidden = true
......@@ -268,7 +293,7 @@ class GameViewController: UIViewController {
let guessedCorrectly = gameEngine.guessLetter(letter: Character(letter))
score.text = "Score : " + String(gameEngine.getScore())
for (wordIndex, word) in wordToGuess.components(separatedBy: " ").enumerated() {
for (wordIndex, word) in wordToGuess.components(separatedBy: .whitespacesAndNewlines).enumerated() {
var updateWord = ""
let wordCharacters = Array(currentWordState[wordIndex])
for (charIndex, char) in word.enumerated() {
......@@ -276,7 +301,6 @@ class GameViewController: UIViewController {
if currentChar.uppercased() == guessedLetter {
updateWord += currentChar
// guessedCorrectly = true
} else {
let currentWordStateChar = String(wordCharacters[charIndex])
updateWord += currentWordStateChar
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment