func (title *TitleState) Update(ui *UI, dt float64) { width, height := termbox.Size() text := "Press any key to play. Press 'y' to face an bat at your own risk!" DrawString(width/8, height/4, text, base.RGB(0, 0, 1), base.RGB(0, 0, 0)) termbox.Flush() event := termbox.PollEvent() for event.Type != termbox.EventKey { event = termbox.PollEvent() } switch event.Ch { case 'y': ui.Transition("batmenu") return case 0: switch event.Key { case termbox.KeyCtrlQ: ui.Pop() return } } // Create a game without bats ui.RegisterState("game", NewGameState(0)) ui.Transition("game") }
func (menu *BatMenuState) Update(ui *UI, dt float64) { width, height := termbox.Size() label := "How many bats?" tryAgain := "Please enter an integer" DrawString(width/2, height/2-4, label, base.RGB(0, 0, 1), base.RGB(0, 0, 0)) numBatstr := DrawTextBox(width/2, height/2, base.RGB(0, 0, 1), base.RGB(0, 0, 0), 4) numBats, err := strconv.ParseInt(numBatstr, 10, 64) for err != nil { DrawString(width/2, height/2-3, tryAgain, base.RGB(0, 0, 1), base.RGB(0, 0, 0)) numBatstr := DrawTextBox(width/2, height/2, base.RGB(0, 0, 1), base.RGB(0, 0, 0), 4) numBats, err = strconv.ParseInt(numBatstr, 10, 64) } ui.RegisterState("game", NewGameState(numBats)) ui.Transition("game") }