Files
doucan/app/internal/game/errors.go
2026-02-19 21:18:12 +08:00

35 lines
946 B
Go

package game
import (
"crypto/rand"
"doudizhu-server/internal/models"
"encoding/hex"
"errors"
"fmt"
)
var (
ErrRoomNotFound = errors.New("room not found")
ErrRoomFull = errors.New("room is full")
ErrGameStarted = errors.New("game already started")
ErrGameNotStarted = errors.New("game not started")
ErrPlayerNotFound = errors.New("player not found")
ErrNotEnoughPlayers = errors.New("not enough players")
ErrPlayerNotReady = errors.New("player not ready")
ErrNotYourTurn = errors.New("not your turn")
ErrCardsNotInHand = errors.New("cards not in hand")
ErrInvalidCardType = errors.New("invalid card type")
ErrCannotBeat = errors.New("cannot beat last play")
ErrCannotPass = errors.New("cannot pass")
)
func generateID() string {
b := make([]byte, 8)
rand.Read(b)
return hex.EncodeToString(b)
}
func cardKey(c models.Card) string {
return fmt.Sprintf("%d_%d", c.Suit, c.Value)
}