Browse Source

limited texas build

master
tangmingyou 4 years ago
parent
commit
22d59dddef
  1. 21
      Makefile
  2. 13
      README.md
  3. 84
      internal/game/table.go
  4. 2
      internal/service/auth.go
  5. 24
      internal/service/table.go
  6. 43
      ws.html

21
Makefile

@ -0,0 +1,21 @@
# Go parameters
GOCMD=GO111MODULE=on go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
all: build
build:
rm -rf target/
mkdir target/
cp etc/config.toml target/config.toml
$(GOBUILD) -o target/texas cmd/main.go
clean:
rm -rf target/
run:
nohup target/texas -conf=target/config.toml -region=sh -zone=sh001 -deploy.env=dev -weight=10 2>&1 > target/texas.log &
stop:
pkill -f target/texas

13
README.md

@ -14,18 +14,5 @@ pbjs -t json api/*.proto > jsproto.json
``` ```
## game process
1. player join (检查筹码...)
2. player ready
3. table begin 发牌
4. 开始流程,大盲注 小盲注
[网易德州扑克规则](http://sports.163.com/special/poker_rule/?ivk_sa=1025883k) [网易德州扑克规则](http://sports.163.com/special/poker_rule/?ivk_sa=1025883k)
跟注规则:
小盲注:房主下一个
大盲注:房主下下一个
跟注/加注:大盲注下一个
只有两人:第一轮小盲注先,后续大盲注先下注

84
internal/game/table.go

@ -225,44 +225,6 @@ func (t *Table) NoticeAllPlayer(message proto.Message) {
} }
} }
// RoundOver 当前回合结束
func (t *Table) RoundOver() error {
// 游戏结束,开牌结算
if t.Stage == 5 || 1 == len(collect.Filter(t.Players, func(i int, p *Player) bool {
return p != nil && p.Status != 7
})) {
return t.cardFightAndSettle()
}
// 开启下一回合, 根据回合发公共牌
switch t.Stage {
case 2: // 发3张公共牌(翻牌)
t.Stage = 3
for i := 0; i < 5; i++ {
if i < 3 {
t.PublicCards[i] = t.Dealer.Deal()
continue
}
// 第4,5张牌置空
t.PublicCards[i] = nil
}
case 3: // 发第4张公共牌(转牌turn)
t.Stage = 4
t.PublicCards[3] = t.Dealer.Deal()
case 4: // 发第5张公共牌(河牌river)
t.Stage = 5
t.PublicCards[4] = t.Dealer.Deal()
}
// 重置一些状态
t.LastPosBetChip = 0
t.RoundRaiseTimes = 0
// 由小盲注或小盲注后第一个未弃牌玩家开始
t.SetNextPlayerWithRoundStart()
return nil
}
// SetNextPlayerWithRoundStart 回合开始, 设置下一个下注玩家 // SetNextPlayerWithRoundStart 回合开始, 设置下一个下注玩家
func (t *Table) SetNextPlayerWithRoundStart() { func (t *Table) SetNextPlayerWithRoundStart() {
nextPos := t.SmallBlindPos nextPos := t.SmallBlindPos
@ -389,6 +351,44 @@ func (t *Table) SetNextPlayer(current int) {
} }
} }
// RoundOver 当前回合结束
func (t *Table) RoundOver() error {
// 游戏结束,开牌结算
if t.Stage == 5 || 1 == len(collect.Filter(t.Players, func(i int, p *Player) bool {
return p != nil && p.Status != 7
})) {
return t.cardFightAndSettle()
}
// 开启下一回合, 根据回合发公共牌
switch t.Stage {
case 2: // 发3张公共牌(翻牌)
t.Stage = 3
for i := 0; i < 5; i++ {
if i < 3 {
t.PublicCards[i] = t.Dealer.Deal()
continue
}
// 第4,5张牌置空
t.PublicCards[i] = nil
}
case 3: // 发第4张公共牌(转牌turn)
t.Stage = 4
t.PublicCards[3] = t.Dealer.Deal()
case 4: // 发第5张公共牌(河牌river)
t.Stage = 5
t.PublicCards[4] = t.Dealer.Deal()
}
// 重置一些状态
t.LastPosBetChip = 0
t.RoundRaiseTimes = 0
// 由小盲注或小盲注后第一个未弃牌玩家开始
t.SetNextPlayerWithRoundStart()
return nil
}
// cardFightAndSettle 斗牌并结算 // cardFightAndSettle 斗牌并结算
func (t *Table) cardFightAndSettle() error { func (t *Table) cardFightAndSettle() error {
var winners []*Player = nil var winners []*Player = nil
@ -470,7 +470,13 @@ func (t *Table) cardFightAndSettle() error {
t.Chip = 0 t.Chip = 0
} }
// 玩家置为待操作状态 // 斗牌结束, 玩家置为待操作状态
for _, p := range t.Players {
if p != nil {
p.WaitBet()
p.SetStatus(8)
}
}
// 手牌: stage(1,2) other // 手牌: stage(1,2) other
// 1.展示其他玩家手牌(组合牌型) // 1.展示其他玩家手牌(组合牌型)

2
internal/service/auth.go

@ -178,7 +178,7 @@ func HandleReqIdentity(client *session.NetClient, msg *api.ReqIdentity) (proto.M
subject, err := DecodeSubject(msg.Token) subject, err := DecodeSubject(msg.Token)
if err != nil { if err != nil {
// client.Close("authorize failed!") // client.Close("authorize failed!")
return nil, err return &api.ResFail{Code: 401, Msg: err.Error()}, nil
} }
account := &session.NetAccount{ account := &session.NetAccount{

24
internal/service/table.go

@ -247,11 +247,14 @@ func HandleReqGameFullStatus(player *game.Player, msg *api.ReqGameFullStatus) (p
} }
resGame := player.GameTable.BuildResGameFullStatus() resGame := player.GameTable.BuildResGameFullStatus()
resGame.PlayerId = player.Id resGame.PlayerId = player.Id
gameEnd := collect.In(player.GameTable.Stage, 1, 7, 9)
// 其他玩家手牌不返回,TODO 计算自己的5张推荐牌 // 其他玩家手牌不返回,TODO 计算自己的5张推荐牌
for _, p := range resGame.Players { if !gameEnd {
if p != nil && p.Id != player.Id { for _, p := range resGame.Players {
p.HandCard[0] = nil if p != nil && p.Id != player.Id {
p.HandCard[1] = nil p.HandCard[0] = nil
p.HandCard[1] = nil
}
} }
} }
return resGame, nil return resGame, nil
@ -264,7 +267,7 @@ func HandleReqReadyStart(player *game.Player, msg *api.ReqReadyStart) (proto.Mes
if player.Id == player.GameTable.MasterId { if player.Id == player.GameTable.MasterId {
return &api.ResFail{Msg: "房主不用准备"}, nil return &api.ResFail{Msg: "房主不用准备"}, nil
} }
if player.Status != 1 { if !collect.In(player.Status, 1, 8) {
msg := "" msg := ""
switch player.Status { switch player.Status {
case 2: case 2:
@ -299,7 +302,7 @@ func HandleReqCancelReady(player *game.Player, msg *api.ReqCancelReady) (proto.M
func HandleReqDismissGameTable(player *game.Player, msg *api.ReqDismissGameTable) (proto.Message, error) { func HandleReqDismissGameTable(player *game.Player, msg *api.ReqDismissGameTable) (proto.Message, error) {
player.GameTable.Lock.Lock() player.GameTable.Lock.Lock()
defer player.GameTable.Lock.Unlock() defer player.GameTable.Lock.Unlock()
if player.GameTable.Stage != 1 { if !collect.In(player.GameTable.Stage, 1, 7) {
return &api.ResFail{Msg: fmt.Sprintf("#%d,牌局进行中", player.GameTable.Stage)}, nil return &api.ResFail{Msg: fmt.Sprintf("#%d,牌局进行中", player.GameTable.Stage)}, nil
} }
player.GameTable.Stage = 9 player.GameTable.Stage = 9
@ -336,7 +339,7 @@ func HandleReqGameStart(player *game.Player, msg *api.ReqGameStart) (proto.Messa
if player.Id != table.MasterId { if player.Id != table.MasterId {
return &api.ResFail{Msg: "你不是房主"}, nil return &api.ResFail{Msg: "你不是房主"}, nil
} }
if table.Stage != 1 { if !collect.In(table.Stage, 1, 7) {
return &api.ResFail{Msg: fmt.Sprintf("牌局状态有误%d", table.Stage)}, nil return &api.ResFail{Msg: fmt.Sprintf("牌局状态有误%d", table.Stage)}, nil
} }
// 检查所有玩家准备状态 // 检查所有玩家准备状态
@ -436,6 +439,9 @@ func HandleReqBetting(player *game.Player, msg *api.ReqBetting) (proto.Message,
if !collect.In(msg.BetType, player.BetOpts...) { if !collect.In(msg.BetType, player.BetOpts...) {
return &api.ResFail{Msg: fmt.Sprintf("当前不可执行该操作#%d", msg.BetType)}, nil return &api.ResFail{Msg: fmt.Sprintf("当前不可执行该操作#%d", msg.BetType)}, nil
} }
if !collect.In(player.GameTable.Stage, 2, 3, 4, 5) {
return &api.ResFail{Msg: fmt.Sprintf("当前阶段不可下注#%d", msg.BetType)}, nil
}
// 投注结束广播牌桌状态 // 投注结束广播牌桌状态
defer player.GameTable.NoticeGameFullStatus() defer player.GameTable.NoticeGameFullStatus()
@ -491,11 +497,11 @@ func HandleReqBetting(player *game.Player, msg *api.ReqBetting) (proto.Message,
betNotice.Line1 = fmt.Sprintf("+%d", msg.BetChip) betNotice.Line1 = fmt.Sprintf("+%d", msg.BetChip)
if playerBettingChip == player.BetMin { if playerBettingChip == player.BetMin {
betNotice.Line2 = "跟注" betNotice.Line2 = fmt.Sprintf("跟注%d", player.BetMin)
} else { } else {
betNotice.Line2 = fmt.Sprintf("加注:%d", msg.BetChip-player.BetMin) betNotice.Line2 = fmt.Sprintf("加注:%d", msg.BetChip-player.BetMin)
if player.BetMin > 0 { if player.BetMin > 0 {
betNotice.Line2 = fmt.Sprintf("跟注:%d", player.BetMin) betNotice.Line3 = fmt.Sprintf("跟注:%d", player.BetMin)
} }
} }

43
ws.html

@ -1,43 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>websocket</title>
</head>
<body>
<input type="text" id="uname">
<button id="btn">连接</button>
<script type="text/javascript">
document.getElementById("btn").onclick = function() {
const uname = document.getElementById("uname").value
console.log(uname)
connect(uname)
}
function connect(uname) {
const ws = new WebSocket("ws://localhost:9999/ws")
ws.onopen = (e) => {
console.log('open', e)
document.getElementById("uname").value = ""
document.getElementById("btn").innerText = '发送'
document.getElementById("btn").onclick = function () {
const msg = document.getElementById("uname").value
const token = "AgOjcdf3goeYDX3lwWWwkXtVpcrL-l2rX8csrRKgs3_-BC3JOx0l6nZU0MV25eIn"
ws.send(JSON.stringify({t: token}))
document.getElementById("uname").value = ''
}
}
ws.onmessage = (e) => {
console.log('msg:', e.data)
}
ws.onerror = (a,b,c) => {
console.log('error:', a, b, c)
}
}
</script>
</body>
</html>
Loading…
Cancel
Save