Skip to content

Commit

Permalink
Merge pull request #21 from g-liu/inf-mode-respect
Browse files Browse the repository at this point in the history
Respect max guesses in Infinite mode + other changes
  • Loading branch information
g-liu authored Mar 10, 2022
2 parents 928a3f6 + a552d35 commit 58e634e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions WordleWithFriends/ClueGuessViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion WordleWithFriends/Models/GameGuessesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class WordleKeyboardInputView: UIInputView {
private var keyReferences: [WeakRef<WordleKeyboardKey>] = []
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 {
Expand All @@ -35,25 +35,14 @@ final class WordleKeyboardInputView: UIInputView {
keyRows[keyRows.count-1].append(WordleKeyboardKey(keyType: .del))

return keyRows
}()
}

var delegate: KeyTapDelegate? {
didSet {
setupKeyboard()
}
}

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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 58e634e

Please sign in to comment.