Skip to content
Snippets Groups Projects
Commit 3328020f authored by Nathan's avatar Nathan
Browse files

add score

parent 40b1bb16
Branches
No related tags found
No related merge requests found
......@@ -403,6 +403,12 @@
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z7p-BQ-fzG">
<rect key="frame" x="335" y="71" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
......@@ -413,6 +419,7 @@
<constraint firstItem="2XB-iI-dfu" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="586" id="GDi-3N-WOL"/>
<constraint firstItem="2XB-iI-dfu" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="18" id="H7Y-qR-xN4"/>
<constraint firstItem="z7N-Ws-jLx" firstAttribute="trailing" secondItem="2XB-iI-dfu" secondAttribute="trailing" id="bRt-Cx-tpa"/>
<constraint firstItem="z7p-BQ-fzG" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="height" multiplier="3:64" id="fYv-Gn-rTp"/>
<constraint firstItem="2XB-iI-dfu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="k43-6H-xEG"/>
<constraint firstItem="z7N-Ws-jLx" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="v2G-KO-OfQ"/>
</constraints>
......
This diff is collapsed.
......@@ -10,17 +10,17 @@ import CoreData
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 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 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 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", "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 listThemeCitiesHard : [String] = ["Copenhague", "Budapest", "Dubrovnik", "Seoul", "Marrakech", "Reykjavik", "La Nouvelle-Orleans", "Bratislava", "Wellington", "Accra"];
private var listThemeColorsHard : [String] = ["ecarlate", "Azur", "emeraude", "Safran", "Pourpre", "Indigo", "Sienne", "Cyan", "Vermillon", "Lavande"];
private var wordToGuess : String = "";
private var attemptsRemaining : Int = 0;
......@@ -39,52 +39,55 @@ class GameEngine: NSObject {
//
}
func WordToGuess(theme: String, difficulty: String) -> String{
var word = ""
func WordToGuess(theme: String, difficulty: String) -> Void{
self.theme = theme;
self.difficulty = difficulty;
if theme == "Animals"{
if difficulty == "Easy"{
let randomInt = Int.random(in: 0..<listThemeAnimalsEasy.count)
word = listThemeAnimalsEasy[randomInt]
self.wordToGuess = listThemeAnimalsEasy[randomInt]
} else {
let randomInt = Int.random(in: 0..<listThemeAnimalsHard.count)
word = listThemeAnimalsHard[randomInt]
self.wordToGuess = listThemeAnimalsHard[randomInt]
}
} else if theme == "Sports"{
if difficulty == "Easy"{
let randomInt = Int.random(in: 0..<listThemeSportsEasy.count)
word = listThemeAnimalsEasy[randomInt]
self.wordToGuess = listThemeAnimalsEasy[randomInt]
} else {
let randomInt = Int.random(in: 0..<listThemeSportsHard.count)
word = listThemeSportsHard[randomInt]
self.wordToGuess = listThemeSportsHard[randomInt]
}
} else if theme == "Food"{
if difficulty == "Easy"{
let randomInt = Int.random(in: 0..<listThemeFoodEasy.count)
word = listThemeFoodEasy[randomInt]
self.wordToGuess = listThemeFoodEasy[randomInt]
} else {
let randomInt = Int.random(in: 0..<listThemeFoodHard.count)
word = listThemeFoodHard[randomInt]
self.wordToGuess = listThemeFoodHard[randomInt]
}
} else if theme == "Cities"{
if difficulty == "Easy"{
let randomInt = Int.random(in: 0..<listThemeCitiesEasy.count)
word = listThemeCitiesEasy[randomInt]
self.wordToGuess = listThemeCitiesEasy[randomInt]
} else {
let randomInt = Int.random(in: 0..<listThemeCitiesHard.count)
word = listThemeCitiesHard[randomInt]
self.wordToGuess = listThemeCitiesHard[randomInt]
}
} else if theme == "Colors"{
if difficulty == "Easy"{
let randomInt = Int.random(in: 0..<listThemeColorsEasy.count)
word = listThemeColorsEasy[randomInt]
self.wordToGuess = listThemeColorsEasy[randomInt]
} else {
let randomInt = Int.random(in: 0..<listThemeColorsHard.count)
word = listThemeColorsHard[randomInt]
self.wordToGuess = listThemeColorsHard[randomInt]
}
}
return word
self.wordToGuess = self.wordToGuess.uppercased()
}
public func getWordToGuess() -> String {
return self.wordToGuess;
}
public func guessLetter(letter: Character) -> Bool {
......@@ -92,6 +95,8 @@ class GameEngine: NSObject {
return false;
}
print("lettre: " + String(letter))
guessedLetters.append(letter);
if wordToGuess.contains(letter) {
......@@ -132,12 +137,14 @@ class GameEngine: NSObject {
}
lastGuessedLetterTime = Date();
print("trouvé, score="+String(score))
return true;
}
remainingLives -= 1;
combo = 0;
lastGuessedLetterTime = nil;
print("pas trouvé")
return false;
}
......
......@@ -31,6 +31,7 @@ extension UIView {
class GameViewController: UIViewController {
@IBOutlet weak var wordLabel: UILabel!
@IBOutlet weak var score: UILabel!
@IBOutlet weak var A_Button: UIButton!
@IBOutlet weak var Z_Button: UIButton!
......@@ -150,7 +151,10 @@ class GameViewController: UIViewController {
var currentWordState: [String] = []
var wordToGuess : String = ""
var gameEngine : GameEngine = GameEngine()
var wordToGuess = ""
var isWordFound = false
......@@ -158,12 +162,17 @@ class GameViewController: UIViewController {
override func viewDidLoad() {
view.addBackground()
wordToGuess = gameEngine.getWordToGuess()
super.viewDidLoad()
print(wordToGuess)
initializeWordState()
updateWordLabel()
updateImage()
score.textColor = UIColor.white
score.text = "Score : 0"
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
label.center = CGPoint(x: 170, y: 230)
label.font = UIFont(name: "whatever it takes", size: 40)
......@@ -228,7 +237,8 @@ class GameViewController: UIViewController {
var updateWordState = currentWordState
var guessedCorrectly = false
let guessedCorrectly = gameEngine.guessLetter(letter: Character(letter))
score.text = "Score : " + String(gameEngine.getScore())
for (wordIndex, word) in wordToGuess.components(separatedBy: " ").enumerated() {
var updateWord = ""
......@@ -238,7 +248,7 @@ class GameViewController: UIViewController {
if currentChar.uppercased() == guessedLetter {
updateWord += currentChar
guessedCorrectly = true
// guessedCorrectly = true
} else {
let currentWordStateChar = String(wordCharacters[charIndex])
updateWord += currentWordStateChar
......@@ -253,7 +263,6 @@ class GameViewController: UIViewController {
if !guessedCorrectly {
updateImage()
}
}
......
......@@ -9,7 +9,7 @@ class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDele
var wordToGuess : String = ""
let pickerData = ["Animals", "Sports", "Food", "Cities", "Colors"]
let gameEngine : GameEngine = GameEngine()
var gameEngine : GameEngine = GameEngine()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -20,7 +20,7 @@ class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDele
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
if segue.identifier == "DeAccueilAJeu" {
let destinationVC = segue.destination as! GameViewController
destinationVC.wordToGuess = wordToGuess
destinationVC.gameEngine = gameEngine
}
}
......@@ -44,7 +44,7 @@ class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDele
// Ajoutez votre code supplémentaire ici
let difficulty = niveau ?? ""
wordToGuess = gameEngine.WordToGuess(theme: theme, difficulty: difficulty)
gameEngine.WordToGuess(theme: theme, difficulty: difficulty)
print("Mot à deviner: \(wordToGuess)")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment