func TitleState(g *game.Game) (State, *game.Game) { ui.Clear() ui.Print(0, 0, "Title State") ui.Update() ui.GetEvent() return MenuState, g }
func LoadState(g *game.Game) (State, *game.Game) { ui.Clear() ui.Print(0, 0, "Loading...") // do actual loading here ui.PrintSliceAtBottom(g.Read(8)) ui.Update() time.Sleep(time.Millisecond * 200) return PlayState, g }
func MenuState(g *game.Game) (State, *game.Game) { var offSet = 4 var current = 0 var printFormat string var ev ui.Event var options = []struct { name string val State }{ {"Play", PlayState}, {"Save", SaveState}, {"Load", LoadState}, {"Exit", ExitState}, } menu: for { ui.Clear() for i := range options { if i == current { printFormat = SelectPrint } else { printFormat = NormalPrint } ui.Print(offSet*2, offSet+i, fmt.Sprintf(printFormat, options[i].name)) } ui.PrintSliceAtBottom(g.Read(8)) ui.Update() switch ev = ui.GetEvent(); ev.Key { case ui.DOWN: if current+1 < len(options) { current++ } case ui.UP: if current-1 > -1 { current-- } case ui.ENTER: break menu } } return options[current].val, g }