plane.go 867 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package gamelogic
  2. type Plane struct {
  3. Id int
  4. Position int // 在机场是0,1表示刚起飞,最多走 13 * 3 + 18
  5. CanMove bool // 当前是否可以移动
  6. // 检测碰撞需要通过椅子号转换判断
  7. }
  8. // 检查是否已经起飞
  9. func (p *Plane) isTookOff() bool {
  10. return p.Position > 0
  11. }
  12. func (p *Plane) isLanded() bool {
  13. return p.Position == MAX_STEP
  14. }
  15. // 获得即将抵达终点距离
  16. func (p *Plane) calculateArriveDistance() int {
  17. //只有进入即将到达区域才计算
  18. if p.isWillArrive() {
  19. return MAX_STEP - p.Position
  20. }
  21. return 0
  22. }
  23. func (p *Plane) isWillArrive() bool {
  24. return p.Position > LOOP_START && p.Position < MAX_STEP
  25. }
  26. func (p *Plane) resetCanMove(number int) {
  27. if p.Position == 0 {
  28. p.CanMove = number == 6
  29. return
  30. }
  31. if p.Position+number > MAX_STEP {
  32. p.CanMove = false
  33. return
  34. }
  35. p.CanMove = true
  36. }