diff --git a/WordleWithFriends/Child ViewControllers/GameMessagingViewController.swift b/WordleWithFriends/Child ViewControllers/GameMessagingViewController.swift index 4de0c3c..e790d69 100644 --- a/WordleWithFriends/Child ViewControllers/GameMessagingViewController.swift +++ b/WordleWithFriends/Child ViewControllers/GameMessagingViewController.swift @@ -46,11 +46,12 @@ final class GameMessagingViewController: UIViewController { alertController.addAction(shareButton) alertController.addAction(mainMenuButton) + mainMenuButton.setValue("Main menu", forKeyPath: "title") + switch gamemode { case .human: - mainMenuButton.setValue("Main menu", forKeyPath: "title") + break case .computer: - mainMenuButton.setValue("Main menu", forKeyPath: "title") alertController.addAction(newClueButton) case .infinite: break // Infinite game mode never touches this VC diff --git a/WordleWithFriends/ClueGuessViewController.swift b/WordleWithFriends/ClueGuessViewController.swift index 0275d96..c07c44a 100644 --- a/WordleWithFriends/ClueGuessViewController.swift +++ b/WordleWithFriends/ClueGuessViewController.swift @@ -245,10 +245,6 @@ extension ClueGuessViewController: UITableViewDelegate, UITableViewDataSource { } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if gameGuessesModel.gamemode == .infinite { - return gameGuessesModel.numberOfGuesses + 1 - } - return GameSettings.maxGuesses.readIntValue() } @@ -384,6 +380,12 @@ extension ClueGuessViewController: KeyTapDelegate { } func didTapMainMenu() { - navigationController?.popViewController(animated: true) + let alertController = DismissableAlertController(title: nil, message: "Return to main menu?", preferredStyle: .alert) + alertController.addAction(.init(title: "Yes", style: .default, handler: { [weak self] _ in + self?.navigationController?.popViewController(animated: true) + })) + alertController.addAction(.init(title: "Cancel", style: .cancel, handler: nil)) + + present(alertController, animated: true) } } diff --git a/WordleWithFriends/Models/GameGuessesModel.swift b/WordleWithFriends/Models/GameGuessesModel.swift index 18d33f1..ab15cfb 100644 --- a/WordleWithFriends/Models/GameGuessesModel.swift +++ b/WordleWithFriends/Models/GameGuessesModel.swift @@ -50,7 +50,7 @@ struct GameGuessesModel { if didGuessCorrectly { isGameOver = true return .win - } else if gamemode != .infinite && letterGuesses.count > GameSettings.maxGuesses.readIntValue() { + } else if letterGuesses.count > GameSettings.maxGuesses.readIntValue() { isGameOver = true return .lose } else { diff --git a/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift b/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift index ad23f41..e663dd2 100644 --- a/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift +++ b/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift @@ -24,7 +24,7 @@ final class WordleKeyboardInputView: UIInputView { private var keyReferences: [WeakRef] = [] private weak var forfeitKey: WordleKeyboardKey? - private let keyboardLayout: [[WordleKeyboardKey]] = { + private var keyboardLayout: [[WordleKeyboardKey]] { let characterRows = ["QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"] var keyRows = characterRows.map { row in row.map { @@ -35,7 +35,7 @@ final class WordleKeyboardInputView: UIInputView { keyRows[keyRows.count-1].append(WordleKeyboardKey(keyType: .del)) return keyRows - }() + } var delegate: KeyTapDelegate? { didSet { @@ -43,17 +43,6 @@ final class WordleKeyboardInputView: UIInputView { } } - private let gamemode: GameMode - - init(gamemode: GameMode) { - self.gamemode = gamemode - super.init(frame: .zero, inputViewStyle: .keyboard) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - private lazy var mainStackView: UIStackView = { let stackView = UIStackView() stackView.translatesAutoresizingMaskIntoConstraints = false @@ -65,6 +54,17 @@ final class WordleKeyboardInputView: UIInputView { return stackView }() + private let gamemode: GameMode + + init(gamemode: GameMode) { + self.gamemode = gamemode + super.init(frame: .zero, inputViewStyle: .keyboard) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + func getPortraitModeKeyWidth() -> CGFloat { let keyboardWidth = UIScreen.main.bounds.width let keyboardRowKeyWidths = keyboardLayout.enumerated().map { index, row -> CGFloat in @@ -134,11 +134,7 @@ final class WordleKeyboardInputView: UIInputView { let operationKeysRow = KeyboardRow() operationKeysRow.delegate = delegate - if gamemode == .infinite { - operationKeysRow.configure(keys: [forfeitKey, mainMenuKey], keyWidth: keyWidth) - } else { - operationKeysRow.configure(keys: [forfeitKey], keyWidth: keyWidth) - } + operationKeysRow.configure(keys: [forfeitKey, mainMenuKey], keyWidth: keyWidth) mainStackView.addArrangedSubview(operationKeysRow)