Skip to content

Commit

Permalink
Merge pull request #37 from aversey/patch-1
Browse files Browse the repository at this point in the history
Tic Tac Toe: Fixes win check on the last turn
  • Loading branch information
andydotxyz authored Mar 30, 2022
2 parents 67fb5fc + f40732a commit 06b751e
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 06b751e

Please sign in to comment.