Updated the examples

This commit is contained in:
Sasha Koshka
2023-04-18 16:18:30 -04:00
parent 14080b1f88
commit 7cdc5868e5
20 changed files with 271 additions and 169 deletions

View File

@@ -12,15 +12,15 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
window.SetTitle("adventure")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
var world flow.Flow
world.Transition = container.DisownAll
world.Stages = map [string] func () {
"start": func () {
label := elements.NewLabel (
"you are standing next to a river.", true)
label := elements.NewLabelWrapped (
"you are standing next to a river.")
button0 := elements.NewButton("go in the river")
button0.OnClick(world.SwitchFunc("wet"))
@@ -29,70 +29,65 @@ func run () {
button2 := elements.NewButton("turn around")
button2.OnClick(world.SwitchFunc("bear"))
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.Adopt(button2, false)
container.AdoptExpand(label)
container.Adopt(button0, button1, button2)
button0.Focus()
},
"wet": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you get completely soaked.\n" +
"you die of hypothermia.", true)
"you die of hypothermia.")
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button0.Focus()
},
"house": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you are standing in front of a delapidated " +
"house.", true)
"house.")
button1 := elements.NewButton("go inside")
button1.OnClick(world.SwitchFunc("inside"))
button0 := elements.NewButton("turn back")
button0.OnClick(world.SwitchFunc("start"))
container.Adopt(label, true)
container.Adopt(button1, false)
container.Adopt(button0, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button1.Focus()
},
"inside": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you are standing inside of the house.\n" +
"it is dark, but rays of light stream " +
"through the window.\n" +
"there is nothing particularly interesting " +
"here.", true)
"here.")
button0 := elements.NewButton("go back outside")
button0.OnClick(world.SwitchFunc("house"))
container.Adopt(label, true)
container.Adopt(button0, false)
container.AdoptExpand(label)
container.Adopt(button0)
button0.Focus()
},
"bear": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you come face to face with a bear.\n" +
"it eats you (it was hungry).", true)
"it eats you (it was hungry).")
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button0.Focus()
},
}