diff --git a/Pendu.xcodeproj/project.pbxproj b/Pendu.xcodeproj/project.pbxproj index 2a176475045c0d3e884bdf7472a6e77b5081f207..20de1145bb9ed6caaf5997be33c7b513159f51f7 100644 --- a/Pendu.xcodeproj/project.pbxproj +++ b/Pendu.xcodeproj/project.pbxproj @@ -17,6 +17,10 @@ BF3C48282A0A1FCD00CE128F /* PenduTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C48272A0A1FCD00CE128F /* PenduTests.swift */; }; BF3C48322A0A1FCD00CE128F /* PenduUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C48312A0A1FCD00CE128F /* PenduUITests.swift */; }; BF3C48342A0A1FCD00CE128F /* PenduUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C48332A0A1FCD00CE128F /* PenduUITestsLaunchTests.swift */; }; + BF3C48432A0A3CFF00CE128F /* GameEngineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C48422A0A3CFF00CE128F /* GameEngineTests.swift */; }; + D082CCC92A0A33D600D97981 /* GameEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D082CCC82A0A33D600D97981 /* GameEngine.swift */; }; + D082CCCA2A0A33D600D97981 /* GameEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D082CCC82A0A33D600D97981 /* GameEngine.swift */; }; + D082CCCB2A0A33D600D97981 /* GameEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D082CCC82A0A33D600D97981 /* GameEngine.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -51,6 +55,8 @@ BF3C482D2A0A1FCD00CE128F /* PenduUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PenduUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; BF3C48312A0A1FCD00CE128F /* PenduUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PenduUITests.swift; sourceTree = "<group>"; }; BF3C48332A0A1FCD00CE128F /* PenduUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PenduUITestsLaunchTests.swift; sourceTree = "<group>"; }; + BF3C48422A0A3CFF00CE128F /* GameEngineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameEngineTests.swift; sourceTree = "<group>"; }; + D082CCC82A0A33D600D97981 /* GameEngine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameEngine.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -109,6 +115,8 @@ BF3C481B2A0A1FCD00CE128F /* LaunchScreen.storyboard */, BF3C481E2A0A1FCD00CE128F /* Info.plist */, BF3C48162A0A1FCA00CE128F /* Pendu.xcdatamodeld */, + D082CCC82A0A33D600D97981 /* GameEngine.swift */, + BF3C48422A0A3CFF00CE128F /* GameEngineTests.swift */, ); path = Pendu; sourceTree = "<group>"; @@ -261,6 +269,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D082CCC92A0A33D600D97981 /* GameEngine.swift in Sources */, BF3C48122A0A1FCA00CE128F /* ViewController.swift in Sources */, BF3C480E2A0A1FCA00CE128F /* AppDelegate.swift in Sources */, BF3C48182A0A1FCA00CE128F /* Pendu.xcdatamodeld in Sources */, @@ -273,6 +282,8 @@ buildActionMask = 2147483647; files = ( BF3C48282A0A1FCD00CE128F /* PenduTests.swift in Sources */, + D082CCCA2A0A33D600D97981 /* GameEngine.swift in Sources */, + BF3C48432A0A3CFF00CE128F /* GameEngineTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -281,6 +292,7 @@ buildActionMask = 2147483647; files = ( BF3C48322A0A1FCD00CE128F /* PenduUITests.swift in Sources */, + D082CCCB2A0A33D600D97981 /* GameEngine.swift in Sources */, BF3C48342A0A1FCD00CE128F /* PenduUITestsLaunchTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Pendu.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Pendu.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000000000000000000000000000000000..f9b0d7c5ea15f194be85eb6ee8e6721a87ff4644 --- /dev/null +++ b/Pendu.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>PreviewsEnabled</key> + <false/> +</dict> +</plist> diff --git a/Pendu/GameEngine.swift b/Pendu/GameEngine.swift new file mode 100644 index 0000000000000000000000000000000000000000..a11054f68a68c6e52f46f370f11dd66a1acdc3f6 --- /dev/null +++ b/Pendu/GameEngine.swift @@ -0,0 +1,107 @@ +// +// 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 + + 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 { + //wordToGuess = WordToGuess(theme: "Animals", difficulty: "Easy") + //} + + public func guessLetter(letter: Character) -> Bool { + + if wordToGuess.contains(letter) { + return true + } else { + return false + } + + } + + 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 + } +} diff --git a/Pendu/GameEngineTests.swift b/Pendu/GameEngineTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..867a9bd872291d200b7d8bed0327f7b4f4866e3a --- /dev/null +++ b/Pendu/GameEngineTests.swift @@ -0,0 +1,32 @@ +// +// GameEngineTests.swift +// PenduTests +// +// Created by Sofiane Lasri-Trienpont on 09/05/2023. +// + +import XCTest + +class GameEngineTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testIsGameOver() throws { + let game:GameEngine = GameEngine(); + XCTAssertEqual(false, game.isGameOver()); + } + + func testStartNewGame() throws { + let game:GameEngine = GameEngine(); + let mot1 = game.WordToGuess(theme: "Sports", difficulty: "Hard") + let mot2 = game.WordToGuess(theme: "Sports", difficulty: "Hard") + XCTAssertNotEqual(mot1, mot2) + } + +} diff --git a/Pendu/Pendu.xcdatamodeld/Pendu.xcdatamodel/contents b/Pendu/Pendu.xcdatamodeld/Pendu.xcdatamodel/contents index 50d2514e87d2e6274170ca7165bbfd11f32c64e3..c446d97726d6a01470796fa216f7c9176d7d3996 100644 --- a/Pendu/Pendu.xcdatamodeld/Pendu.xcdatamodel/contents +++ b/Pendu/Pendu.xcdatamodeld/Pendu.xcdatamodel/contents @@ -1,4 +1,12 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="false" userDefinedModelVersionIdentifier=""> - <elements/> +<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21E258" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""> + <entity name="Scoreboard" representedClassName="Scoreboard" syncable="YES" codeGenerationType="class"> + <attribute name="categoryName" optional="YES" attributeType="String"/> + <attribute name="difficulty" optional="YES" attributeType="String"/> + <attribute name="playerName" optional="YES" attributeType="String"/> + <attribute name="score" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/> + </entity> + <elements> + <element name="Scoreboard" positionX="-63" positionY="-18" width="128" height="89"/> + </elements> </model> \ No newline at end of file diff --git a/PenduTests/PenduTests.swift b/PenduTests/PenduTests.swift index d659345db8cafa5fdd6de0292abc93547ad1b6e9..b960a7496e65129377ed43b4c8533080a84deec9 100644 --- a/PenduTests/PenduTests.swift +++ b/PenduTests/PenduTests.swift @@ -32,5 +32,5 @@ class PenduTests: XCTestCase { // Put the code you want to measure the time of here. } } - + }