plane.go 829 B

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