Draft: big refactor
This commit is contained in:
48
server/wordle/handlers.go
Normal file
48
server/wordle/handlers.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package wordle
|
||||
|
||||
import "gitea.konchin.com/ytshih/inp2025/game/types"
|
||||
|
||||
type OperationType int
|
||||
|
||||
const (
|
||||
OperationTypeGuess OperationType = iota
|
||||
)
|
||||
|
||||
type Operation struct {
|
||||
Type OperationType
|
||||
Username string
|
||||
Guess string
|
||||
}
|
||||
|
||||
type Handlers struct {
|
||||
state WordleState
|
||||
ans string
|
||||
|
||||
opCh chan Operation
|
||||
subs []*chan types.WordleState
|
||||
}
|
||||
|
||||
func NewHandlers() *Handlers {
|
||||
ret := &Handlers{subs: nil}
|
||||
go ret.GameFlow()
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *Handlers) GameFlow() {
|
||||
for op := range self.opCh {
|
||||
switch op.Type {
|
||||
case OperationTypeGuess:
|
||||
self.state.CurrentGuess++
|
||||
if self.state.CurrentGuess >= len(self.Users) {
|
||||
for i := range self.Users {
|
||||
self.Users[i].History = append(self.Users[i].History,
|
||||
types.NewWord(input, ans))
|
||||
}
|
||||
}
|
||||
|
||||
for _, sub := range self.subs {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user