Fixed bug, where the popup window opened twice.

This commit is contained in:
Falko Victor Habel 2024-04-29 15:32:13 +02:00
parent d208a51419
commit bfc55afb14
1 changed files with 6 additions and 0 deletions

View File

@ -82,10 +82,14 @@ func Gameloop(row, col int, Window fyne.Window) {
// checking if the game has been won by the human player // checking if the game has been won by the human player
if gameControl.PlayerHasWon(board, PLAYER_X) { if gameControl.PlayerHasWon(board, PLAYER_X) {
dialog.ShowInformation(gameOverText, "X has won!", Window) dialog.ShowInformation(gameOverText, "X has won!", Window)
DisableAllButtons(gridContainer)
return
} }
// checking if the game is a draw // checking if the game is a draw
if gameControl.BoardisFull(board) { if gameControl.BoardisFull(board) {
dialog.ShowInformation(gameOverText, "It's a draw!", Window) dialog.ShowInformation(gameOverText, "It's a draw!", Window)
DisableAllButtons(gridContainer)
return
} }
// AI opponent makes a move // AI opponent makes a move
bestMove := opponent.Minimax(board, 0, true, PLAYER_O) bestMove := opponent.Minimax(board, 0, true, PLAYER_O)
@ -97,11 +101,13 @@ func Gameloop(row, col int, Window fyne.Window) {
if gameControl.PlayerHasWon(board, PLAYER_O) { if gameControl.PlayerHasWon(board, PLAYER_O) {
dialog.ShowInformation(gameOverText, "O has won!", Window) dialog.ShowInformation(gameOverText, "O has won!", Window)
DisableAllButtons(gridContainer) DisableAllButtons(gridContainer)
return
} }
// checking if the game is a draw // checking if the game is a draw
if gameControl.BoardisFull(board) { if gameControl.BoardisFull(board) {
dialog.ShowInformation(gameOverText, "It's a draw!", Window) dialog.ShowInformation(gameOverText, "It's a draw!", Window)
DisableAllButtons(gridContainer) DisableAllButtons(gridContainer)
return
} }
} }