You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.go 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package core
  2. import (
  3. thuai6 "API/thuai6"
  4. )
  5. type ILogic interface {
  6. Move(time int64, angle float64) bool
  7. TryConnection() bool
  8. GetStudentSelfInfo() *thuai6.Student
  9. GetTrickerSelfInfo() *thuai6.Tricker
  10. }
  11. type StudentAPI struct {
  12. logic ILogic
  13. }
  14. type TrickerAPI struct {
  15. logic ILogic
  16. }
  17. func NewStudentAPI(logic ILogic) *StudentAPI {
  18. return &StudentAPI{
  19. logic: logic,
  20. }
  21. }
  22. func NewTrickerAPI(logic ILogic) *TrickerAPI {
  23. return &TrickerAPI{
  24. logic: logic,
  25. }
  26. }
  27. func (api *StudentAPI) Move(timeInMilliseconds int64, angleInRadian float64) <-chan bool {
  28. res := make(chan bool, 1)
  29. go func() {
  30. res <- api.logic.Move(timeInMilliseconds, angleInRadian)
  31. }()
  32. return res
  33. }
  34. func (api *StudentAPI) GetSelfInfo() *thuai6.Student {
  35. return api.logic.GetStudentSelfInfo()
  36. }
  37. func (api *StudentAPI) StartTimer() {
  38. // Nothing
  39. }
  40. func (api *StudentAPI) EndTimer() {
  41. // Nothing
  42. }
  43. func (api *StudentAPI) Play(ai thuai6.IAI) {
  44. ai.StudentPlay(api)
  45. }
  46. func (api *TrickerAPI) Move(timeInMilliseconds int64, angleInRadian float64) <-chan bool {
  47. res := make(chan bool, 1)
  48. go func() {
  49. res <- api.logic.Move(timeInMilliseconds, angleInRadian)
  50. }()
  51. return res
  52. }
  53. func (api *TrickerAPI) GetSelfInfo() *thuai6.Tricker {
  54. return api.logic.GetTrickerSelfInfo()
  55. }
  56. func (api *TrickerAPI) StartTimer() {
  57. // Nothing
  58. }
  59. func (api *TrickerAPI) EndTimer() {
  60. // Nothing
  61. }
  62. func (api *TrickerAPI) Play(ai thuai6.IAI) {
  63. ai.TrickerPlay(api)
  64. }