Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tic Tac Toe: Fixes win check on the last turn #37

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tictactoe/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ func (b *board) result() uint8 {
func (b *board) newClick(row, column int) {
b.pieces[row][column] = b.turn%2 + 1

if b.turn > 3 && b.turn < 8 {
if b.turn > 3 {
winner := b.result()
if winner == 0 {
if b.turn == 8 {
dialog.ShowInformation("It is a tie!", "Nobody has won. Better luck next time.", fyne.CurrentApp().Driver().AllWindows()[0])
b.finished = true
}
return
}

number := string(winner + 48) // Number 1 is ascii #49 and 2 is ascii #50.
dialog.ShowInformation("Player "+number+" has won!", "Congratulations to player "+number+" for winning.", fyne.CurrentApp().Driver().AllWindows()[0])
b.finished = true
} else if b.turn == 8 {
dialog.ShowInformation("It is a tie!", "Nobody has won. Better luck next time.", fyne.CurrentApp().Driver().AllWindows()[0])
b.finished = true
}
}

Expand Down