turtlesoup.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //海龟汤游戏特定的 API
  2. import { TurtleSoupGame } from '@/stores/games/turtlesoup'
  3. import { callCloudFunction } from '../../cloud'
  4. import { type ITurtleSoupGame, type ITurtleSoupQuestion, type ITurtleSoupGameResult } from '@/types/games/turtlesoup'
  5. // 海龟汤游戏相关API
  6. export const turtleSoupService = {
  7. /**
  8. * 获取游戏数据
  9. * @param gameId 游戏ID
  10. * @param role 用户角色
  11. */
  12. getGameData(gameId: string, role: string) {
  13. return callCloudFunction<{ game: TurtleSoupGame }>('getTurtleSoupGame', { gameId, role })
  14. },
  15. /**
  16. * 提交问题
  17. * @param gameId 游戏ID
  18. * @param content 问题内容
  19. */
  20. submitQuestion(gameId: string, content: string) {
  21. return callCloudFunction<{ questionId: string }>('submitTurtleSoupQuestion', { gameId, content })
  22. },
  23. /**
  24. * 回答问题
  25. * @param questionId 问题ID
  26. * @param answer 答案
  27. */
  28. answerQuestion(questionId: string, answer: string) {
  29. return callCloudFunction<{ success: boolean }>('answerTurtleSoupQuestion', { questionId, answer })
  30. },
  31. /**
  32. * 公开提示
  33. * @param gameId 游戏ID
  34. * @param hintIndex 提示索引
  35. */
  36. revealHint(gameId: string, hintIndex: number) {
  37. return callCloudFunction<{ success: boolean }>('revealTurtleSoupHint', { gameId, hintIndex })
  38. },
  39. /**
  40. * 结束游戏
  41. * @param gameId 游戏ID
  42. * @param result 游戏结果
  43. */
  44. endGame(gameId: string, result: { solved: boolean; solvedBy?: string }) {
  45. return callCloudFunction<{ gameResult: ITurtleSoupGameResult }>('endTurtleSoupGame', { gameId, result })
  46. }
  47. }