Draft: big refactor
This commit is contained in:
83
types/wordle.go
Normal file
83
types/wordle.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type CharStatus int
|
||||
|
||||
const (
|
||||
CharStatusA CharStatus = iota
|
||||
CharStatusB
|
||||
CharStatusC
|
||||
)
|
||||
|
||||
type Char struct {
|
||||
Char rune `msgpack:"char"`
|
||||
Status CharStatus `msgpack:"status"`
|
||||
}
|
||||
|
||||
func NewChar() Char {
|
||||
return Char{
|
||||
Char: 0x0,
|
||||
Status: CharStatusC,
|
||||
}
|
||||
}
|
||||
|
||||
func (self Char) View() string {
|
||||
style := lipgloss.NewStyle()
|
||||
|
||||
switch self.Status {
|
||||
case CharStatusA:
|
||||
style = style.Background(lipgloss.Color("#00ff00"))
|
||||
case CharStatusB:
|
||||
style = style.Background(lipgloss.Color("#ffff00"))
|
||||
case CharStatusC:
|
||||
style = style.Background(lipgloss.Color("#808080"))
|
||||
}
|
||||
|
||||
return style.Render(string(self.Char))
|
||||
}
|
||||
|
||||
type Word struct {
|
||||
Chars []Char `msgpack:"chars"`
|
||||
}
|
||||
|
||||
func NewWord() Word {
|
||||
return Word{
|
||||
Chars: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (self Word) View() string {
|
||||
var b strings.Builder
|
||||
|
||||
for _, char := range self.Chars {
|
||||
b.WriteString(char.View())
|
||||
b.WriteRune('\n')
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
const (
|
||||
MaxLength = 5
|
||||
)
|
||||
|
||||
type UserState struct {
|
||||
History []Word `msgpack:"history"`
|
||||
Input string
|
||||
}
|
||||
|
||||
type WordleState struct {
|
||||
Users map[string]UserState `msgpack:"users"`
|
||||
CurrentGuess int
|
||||
}
|
||||
|
||||
func NewWordleState() WordleState {
|
||||
return WordleState{
|
||||
Users: nil,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user