初始化斗地主残局版项目
This commit is contained in:
34
app/internal/game/errors.go
Normal file
34
app/internal/game/errors.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user