Skeleton of prototypical UI.
This commit is contained in:
37
cardsim/terminalui.go
Normal file
37
cardsim/terminalui.go
Normal file
@ -0,0 +1,37 @@
|
||||
package cardsim
|
||||
|
||||
func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
||||
for {
|
||||
err := p.StartNextTurn()
|
||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||
return err
|
||||
}
|
||||
p.ReportError(err)
|
||||
|
||||
for p.CanAct() {
|
||||
isCard, cardIdx, choiceIdx := pickNextAction(p)
|
||||
var msg Message
|
||||
if isCard {
|
||||
msg, err = p.EnactCard(cardIdx, choiceIdx)
|
||||
} else {
|
||||
msg, err = p.EnactPermanentAction(cardIdx, choiceIdx)
|
||||
}
|
||||
p.ReportError(err)
|
||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||
return err
|
||||
}
|
||||
displayAndWait(msg)
|
||||
}
|
||||
|
||||
review(p)
|
||||
err = p.Simulate()
|
||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.DebugLevel < 1 && p.State.Over() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user