update
This commit is contained in:
parent
36a37c8c7c
commit
70f51721a0
@ -12,9 +12,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxPs = 2 // 最大体力
|
||||
MaxRound = 7 // 最大回合数
|
||||
MaxTime = 180 // 游戏操作时间
|
||||
MaxPs = 2 // 最大体力
|
||||
MaxRound = 7 // 最大回合数
|
||||
MaxTime = 1800 // 游戏操作时间
|
||||
AITime = 4 // AI延迟操作时间操作时间 随机+-3
|
||||
)
|
||||
|
||||
//游戏房间
|
||||
@ -54,7 +55,7 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
Data: this.chessboard.Plat,
|
||||
})
|
||||
//this.module.Debugf("超时%d", configure.Now().Unix())
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
Power: this.power,
|
||||
Score: 0,
|
||||
@ -103,6 +104,7 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
if this.aiTimer != nil {
|
||||
timewheel.Remove(this.aiTimer)
|
||||
}
|
||||
|
||||
// 交换元素
|
||||
bSwap := this.chessboard.AiSwapGirde() // 交换格子
|
||||
if !bSwap {
|
||||
@ -123,7 +125,7 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
}
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器
|
||||
// 广播消息
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
Power: this.power,
|
||||
Score: curScore,
|
||||
@ -177,7 +179,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
if this.aiTimer != nil {
|
||||
timewheel.Remove(this.aiTimer)
|
||||
}
|
||||
this.aiTimer = timewheel.Add(time.Second*MaxTime, this.AiTimeOut)
|
||||
this.aiTimer = timewheel.Add(time.Second*AITime, this.AiTimeOut)
|
||||
}
|
||||
this.round++
|
||||
}
|
||||
@ -195,7 +197,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
|
||||
// 广播消息
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
Power: this.power,
|
||||
Score: curScore,
|
||||
@ -206,9 +208,22 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
this.Errorln(err)
|
||||
}
|
||||
case "ready":
|
||||
this.StartGame()
|
||||
if len(this.szSession) == 1 { // AI对战的话直接开始游戏
|
||||
if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Mpadata: &pb.MapData{
|
||||
Data: this.chessboard.Plat,
|
||||
},
|
||||
Power: this.power,
|
||||
Round: this.round,
|
||||
}, session); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut)
|
||||
}
|
||||
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut)
|
||||
}
|
||||
|
||||
return
|
||||
@ -224,7 +239,7 @@ func (this *Room) Opertor(uid string, iType int32, old int32, new int32) (errdat
|
||||
|
||||
func (this *Room) StartGame() (errdata *pb.ErrorData) {
|
||||
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{
|
||||
if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Mpadata: &pb.MapData{
|
||||
@ -246,7 +261,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
||||
if this.operatetimer != nil {
|
||||
timewheel.Remove(this.operatetimer)
|
||||
}
|
||||
this.SendMsgToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
|
||||
this.module.SendMsgToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Mpadata: &pb.MapData{
|
||||
|
@ -68,6 +68,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
|
||||
}
|
||||
return
|
||||
}
|
||||
firstLogin = true
|
||||
expand = &pb.DBUserExpand{}
|
||||
}
|
||||
// 玩家是否已在线
|
||||
|
Loading…
Reference in New Issue
Block a user