-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
57 lines (46 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//go:generate fyne bundle --package=main -o data.go Icon.png
// Package main launches the solitaire app
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
// show creates a new game and loads a table rendered in a new window.
func show(app fyne.App) {
game := NewGame()
table := NewTable(game)
w := app.NewWindow("Solitaire")
shuffle := widget.NewToolbarAction(theme.ViewRefreshIcon(), func() {
table.game.Hand.Shuffle()
})
table.shuffle = shuffle
bar := widget.NewToolbar(
widget.NewToolbarAction(theme.ContentAddIcon(), func() {
checkRestart(table, w)
}),
shuffle)
w.SetContent(container.NewBorder(bar, nil, nil, nil, table))
w.Resize(fyne.NewSize(minWidth, minHeight))
w.Show()
}
func checkRestart(t *Table, w fyne.Window) {
dialog.ShowConfirm("New Game", "Start a new game?", func(ok bool) {
if !ok {
return
}
t.Restart()
}, w)
}
func shuffleDraw(t *Table) {
}
func main() {
a := app.New()
a.SetIcon(resourceIconPng)
a.Settings().SetTheme(newGameTheme())
show(a)
a.Run()
}