2024-04-23 08:25:40 +00:00
|
|
|
package game
|
2024-04-23 11:54:28 +00:00
|
|
|
|
|
|
|
import (
|
2024-04-25 06:34:25 +00:00
|
|
|
"tictactoe/theme"
|
|
|
|
|
2024-04-23 11:54:28 +00:00
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/app"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/layout"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
// creates a window for the TicTacToe game application.
|
|
|
|
func CreateWindow() fyne.Window {
|
|
|
|
// Create the app.
|
2024-04-25 06:34:25 +00:00
|
|
|
App := app.New()
|
2024-04-23 11:54:28 +00:00
|
|
|
|
2024-04-25 06:34:25 +00:00
|
|
|
// Adding a theme to my Window
|
|
|
|
App.Settings().SetTheme(theme.TicTacToeTheme{})
|
2024-04-23 11:54:28 +00:00
|
|
|
// Create a new window for the game application.
|
2024-04-25 06:34:25 +00:00
|
|
|
Window := App.NewWindow("TicTacToe")
|
2024-04-23 11:54:28 +00:00
|
|
|
|
2024-04-23 19:12:46 +00:00
|
|
|
// create the 3x3 Button grid
|
2024-04-29 08:19:59 +00:00
|
|
|
matchField := MakeButtonGrid(3, 3, Window)
|
2024-04-23 19:12:46 +00:00
|
|
|
// Create a new button and a handler function, if it gets pressed.
|
2024-04-23 11:54:28 +00:00
|
|
|
restartButton := widget.NewButton("Restart", func() {
|
2024-04-23 19:12:46 +00:00
|
|
|
ResetButtonTexts(matchField)
|
2024-04-23 11:54:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// vertical box layout containg the top Items, here the textlabel and the button.
|
2024-04-29 08:19:59 +00:00
|
|
|
topItems := container.NewVBox(restartButton)
|
2024-04-23 11:54:28 +00:00
|
|
|
|
2024-04-23 19:12:46 +00:00
|
|
|
// Generate content for the window using a border layout with the topItems and matchField as the children
|
|
|
|
content := container.New(layout.NewBorderLayout(topItems, nil, nil, nil), topItems, matchField)
|
2024-04-23 11:54:28 +00:00
|
|
|
|
|
|
|
// Set the content and size of the window.
|
2024-04-25 06:34:25 +00:00
|
|
|
Window.SetContent(content)
|
|
|
|
Window.Resize(fyne.NewSize(300, 300))
|
2024-04-23 11:54:28 +00:00
|
|
|
|
|
|
|
// Return the created window.
|
2024-04-25 06:34:25 +00:00
|
|
|
return Window
|
2024-04-23 11:54:28 +00:00
|
|
|
}
|