diff --git a/cardsim/terminalui.go b/cardsim/terminalui.go index 022a53f..7283528 100644 --- a/cardsim/terminalui.go +++ b/cardsim/terminalui.go @@ -1,5 +1,11 @@ package cardsim +import ( + "fmt" + "strconv" + "strings" +) + func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error { for { err := p.StartNextTurn() @@ -35,3 +41,81 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error { } return nil } + +func displayAndWait(m Message) { + if m == nil { + return + } + fmt.Println(m.String()) + wait() +} + +func wait() { + fmt.Println() + fmt.Println("") + fmt.Scanln() +} + +func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int) { + cls() + needsDivider := displayMessageSection(p) + if needsDivider { + divider() + } + displayPrompt(p) + actionsOffset := displayStatsMenu(p) + handOffset := displayPermanentActionsMenu(p, actionsOffset) + max := displayHandMenu(p, handOffset) + + divider() + var input string + fmt.Printf("Show just (M)essages, (S)tats, (A)ctions, make a choice (1-%d), or (Q)uit? >", max+1) + fmt.Scanln(&input) + input = strings.TrimSpace(input) + input = strings.ToLower(input) + switch input { + // Special cases + case "m": + cls() + displayMessageSection(p) + wait() + case "s": + statsMode(p) + case "a": + actionsMode(p) + case "q": + confirmQuit() + default: + i, err := strconv.Atoi(input) + if err != nil { + fmt.Println("Sorry, I don't understand.") + wait() + return pickNextAction(p) + } + if i > max { + fmt.Println("That's not a valid action.") + wait() + return pickNextAction(p) + } + i -= 1 + if i < actionsOffset { + cls() + DisplayOnePanelAndWait(p, i) + } else if i < handOffset { + cls() + i -= actionsOffset + option, ok := promptPermanentAction(p, i) + if ok { + return false, i, option + } + } else { + cls() + i -= handOffset + option, ok := promptCard(p, i) + if ok { + return true, i, option + } + } + } + return pickNextAction(p) +}