File size: 2,934 Bytes
8beb1aa
 
 
 
 
 
 
 
 
 
 
0344b6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8beb1aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import axios from 'axios';

const API_BASE = import.meta.env.VITE_API_URL || '/api';

const api = axios.create({
  baseURL: API_BASE,
  headers: {
    'Content-Type': 'application/json',
  },
});

// Helper functions for easier usage
export const createQuickGame = async (playerName, theme = 'classic') => {
  const response = await api.post('/games/quick-create', { theme, player_name: playerName });
  return response.data;
};

export const joinGame = async (gameId, playerName) => {
  const response = await api.post('/games/join', { game_id: gameId, player_name: playerName });
  return response.data;
};

export const startGame = async (gameId, playerId) => {
  const response = await api.post(`/games/${gameId}/start`, { player_id: playerId });
  return response.data;
};

export const getGameState = async (gameId, playerId) => {
  const response = await api.get(`/games/${gameId}/state/${playerId}`);
  return response.data;
};

export const rollDice = async (gameId, playerId) => {
  const response = await api.post(`/games/${gameId}/roll`, { player_id: playerId });
  return response.data;
};

export const makeSuggestion = async (gameId, playerId, suspect, weapon, room) => {
  const response = await api.post(`/games/${gameId}/suggest`, {
    player_id: playerId,
    suspect,
    weapon,
    room,
  });
  return response.data;
};

export const makeAccusation = async (gameId, playerId, suspect, weapon, room) => {
  const response = await api.post(`/games/${gameId}/accuse`, {
    player_id: playerId,
    suspect,
    weapon,
    room,
  });
  return response.data;
};

export const passTurn = async (gameId, playerId) => {
  const response = await api.post(`/games/${gameId}/pass`, { player_id: playerId });
  return response.data;
};

export const gameAPI = {
  // Get available themes
  getThemes: () => api.get('/themes'),

  // Quick create with defaults
  quickCreate: (theme, playerName) =>
    api.post('/games/quick-create', { theme, player_name: playerName }),

  // Join existing game
  join: (gameId, playerName) =>
    api.post('/games/join', { game_id: gameId, player_name: playerName }),

  // Start game
  start: (gameId) => api.post(`/games/${gameId}/start`),

  // Get game state
  getState: (gameId, playerId) => api.get(`/games/${gameId}/state/${playerId}`),

  // Roll dice
  rollDice: (gameId, playerId) =>
    api.post(`/games/${gameId}/roll`, { player_id: playerId }),

  // Make suggestion
  suggest: (gameId, playerId, suspect, weapon, room) =>
    api.post(`/games/${gameId}/suggest`, {
      player_id: playerId,
      suspect,
      weapon,
      room,
    }),

  // Make accusation
  accuse: (gameId, playerId, suspect, weapon, room) =>
    api.post(`/games/${gameId}/accuse`, {
      player_id: playerId,
      suspect,
      weapon,
      room,
    }),

  // Pass turn
  pass: (gameId, playerId) =>
    api.post(`/games/${gameId}/pass`, { player_id: playerId }),
};

export default api;