#25 Name Wordle
Published in
Dec 12, 2022
目的:結合之前所學的技術,完成這次的作業
學習重點
- enum
- while迴圈
- DispatchQueue.main.asyncAfter
Struct建立題目
struct Question {
let words = ["Alvin", "Angus", "Barry", "Byran", "Blake", "Cecil", "Clark", "Cyril", "Derek", "Duane", "Dwane", "Edgar", "Enoch", "Felix", "Floyd", "Frank", "Oscar", "Peter", "Simon", "Lance", "Louis", "Kevin", "Gavin", "Henry", "Robin", "Roger"]
func getQuestion() -> String {
let randomWord = words.randomElement()!
return randomWord.uppercased()
}
}
enum枚舉
enum Result {
case correct
case unlocated
case wrong
var emoji: String {
switch self {
case .correct:
return "🟩"
case .unlocated:
return "🟫"
case .wrong:
return "⬜️"
}
}
}
完整程式碼
Demo