gamescene.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package gamelogic
  2. import "bet24.com/log"
  3. // 操作结果
  4. type ActionResult struct {
  5. Action int //动作信息
  6. Number int //骰子数值
  7. PlaneId int //操作棋子ID
  8. OldPosition int //棋子原来的位置
  9. Position int //棋子移动位置
  10. CrashedChairId int //被撞击座位
  11. CrashedPlaneId int //被撞击棋子ID
  12. }
  13. type GameScene struct {
  14. Index int
  15. Phase int
  16. WhoseTurn int
  17. LastTurn int
  18. ActionResult ActionResult // 操作信息
  19. Players []PlayerInfo
  20. LeftSec int //本阶段剩余时间
  21. tableId int
  22. userActions []userAction
  23. pool int
  24. base int
  25. }
  26. func (gs *GameScene) dump(includeAction bool) {
  27. log.Debug("====GameScene Table[%d] Index[%d] pool[%d]====", gs.tableId, gs.Index, gs.pool)
  28. log.Debug(" Phase[%d] WhoseTurn[%d] LastTurn[%d]", gs.Phase, gs.WhoseTurn, gs.LastTurn)
  29. log.Debug(" Users:%d", gs.getValidUserCount())
  30. for i := 0; i < CHAIR_COUNT; i++ {
  31. if !gs.Players[i].IsValid {
  32. continue
  33. }
  34. gs.Players[i].dump(i)
  35. }
  36. if includeAction && len(gs.userActions) > 0 {
  37. log.Debug(" Actions:%d", len(gs.userActions))
  38. for _, v := range gs.userActions {
  39. v.dump()
  40. }
  41. }
  42. log.Debug("---------------------------")
  43. }
  44. func newGameScene(tableId int) *GameScene {
  45. gs := new(GameScene)
  46. gs.ctor()
  47. gs.initData(tableId)
  48. return gs
  49. }
  50. func (gs *GameScene) ctor() {
  51. gs.Players = make([]PlayerInfo, CHAIR_COUNT)
  52. }
  53. func (gs *GameScene) initData(tableId int) {
  54. gs.userActions = []userAction{}
  55. for i := 0; i < CHAIR_COUNT; i++ {
  56. gs.Players[i].initData(0, 0, 0)
  57. }
  58. gs.pool = 0
  59. gs.LeftSec = 0
  60. gs.tableId = tableId
  61. gs.gameInit(CHAIR_COUNT)
  62. }
  63. func (gs *GameScene) gameInit(whoseTurn int) {
  64. gs.Index = 0
  65. gs.Phase = Phase_Free
  66. gs.WhoseTurn = whoseTurn
  67. gs.LastTurn = -1
  68. gs.initActionResult()
  69. for i := 0; i < CHAIR_COUNT; i++ {
  70. gs.Players[i].gameInit()
  71. }
  72. }