2024-04-23 08:25:40 +00:00
|
|
|
package game
|
2024-04-23 11:54:28 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/app"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/layout"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
var TextLabel *widget.Label
|
|
|
|
|
|
|
|
// creates a window for the TicTacToe game application.
|
|
|
|
func CreateWindow() fyne.Window {
|
|
|
|
// Create the app.
|
|
|
|
myApp := app.New()
|
|
|
|
|
|
|
|
// Create a new window for the game application.
|
|
|
|
myWindow := myApp.NewWindow("TicTacToe")
|
|
|
|
|
|
|
|
// Set the text of our TextLabel to TicTacToe
|
|
|
|
TextLabel = widget.NewLabel("TicTacToe")
|
2024-04-23 19:12:46 +00:00
|
|
|
// create the 3x3 Button grid
|
|
|
|
matchField := MakeButtonGrid(3, 3)
|
|
|
|
// 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.
|
|
|
|
topItems := container.NewVBox(TextLabel, restartButton)
|
|
|
|
|
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.
|
|
|
|
myWindow.SetContent(content)
|
|
|
|
myWindow.Resize(fyne.NewSize(300, 300))
|
|
|
|
|
|
|
|
// Return the created window.
|
|
|
|
return myWindow
|
|
|
|
}
|