初始化斗地主残局版项目
This commit is contained in:
103
app/internal/models/models.go
Normal file
103
app/internal/models/models.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package models
|
||||
|
||||
type Suit int
|
||||
|
||||
const (
|
||||
SuitHeart Suit = iota
|
||||
SuitDiamond
|
||||
SuitClub
|
||||
SuitSpade
|
||||
SuitJoker
|
||||
SuitSuper
|
||||
)
|
||||
|
||||
type Card struct {
|
||||
Suit Suit `json:"suit"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
type CardType int
|
||||
|
||||
const (
|
||||
CardTypeInvalid CardType = iota
|
||||
CardTypeSingle
|
||||
CardTypePair
|
||||
CardTypeTriple
|
||||
CardTypeTripleOne
|
||||
CardTypeTriplePair
|
||||
CardTypeStraight
|
||||
CardTypeDoubleStraight
|
||||
CardTypeBomb
|
||||
CardTypeRocket
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cards []Card `json:"cards,omitempty"`
|
||||
CardCount int `json:"cardCount"`
|
||||
IsReady bool `json:"isReady"`
|
||||
IsOnline bool `json:"isOnline"`
|
||||
}
|
||||
|
||||
type RoomState int
|
||||
|
||||
const (
|
||||
RoomStateWaiting RoomState = iota
|
||||
RoomStatePlaying
|
||||
RoomStateFinished
|
||||
)
|
||||
|
||||
type PlayRecord struct {
|
||||
PlayerID string `json:"playerId"`
|
||||
Cards []Card `json:"cards"`
|
||||
CardType CardType `json:"cardType"`
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
ID string `json:"id"`
|
||||
Players []*Player `json:"players"`
|
||||
CurrentTurn int `json:"currentTurn"`
|
||||
State RoomState `json:"state"`
|
||||
LastPlay *PlayRecord `json:"lastPlay,omitempty"`
|
||||
LastWinner string `json:"lastWinner,omitempty"`
|
||||
RoundCount int `json:"roundCount"`
|
||||
MaxPlayers int `json:"maxPlayers"`
|
||||
}
|
||||
|
||||
type MessageType string
|
||||
|
||||
const (
|
||||
MsgTypeJoin MessageType = "join"
|
||||
MsgTypeLeave MessageType = "leave"
|
||||
MsgTypeReady MessageType = "ready"
|
||||
MsgTypePlay MessageType = "play"
|
||||
MsgTypePass MessageType = "pass"
|
||||
MsgTypeState MessageType = "state"
|
||||
MsgTypeError MessageType = "error"
|
||||
MsgTypeChat MessageType = "chat"
|
||||
MsgTypeGameOver MessageType = "gameOver"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Type MessageType `json:"type"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ApiResponse struct {
|
||||
Status int `json:"status"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateRoomRequest struct {
|
||||
PlayerName string `json:"playerName"`
|
||||
MaxPlayers int `json:"maxPlayers"`
|
||||
}
|
||||
|
||||
type JoinRoomRequest struct {
|
||||
PlayerName string `json:"playerName"`
|
||||
}
|
||||
Reference in New Issue
Block a user