-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
63 lines (52 loc) · 1.27 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
58
59
60
61
62
63
//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))
game.OnWin = func() {
table.finishAnimation()
d := dialog.NewInformation("You Win!", "Congratulations", w)
d.SetOnClosed(table.Restart)
d.Show()
}
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()
}