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