Initial commit: Своя Игра - multiplayer quiz game
This commit is contained in:
46
server/src/routes/games.js
Normal file
46
server/src/routes/games.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Создать новую игру
|
||||
router.post('/create', (req, res) => {
|
||||
try {
|
||||
const gameCode = nanoid(6).toUpperCase();
|
||||
const { teamName } = req.body;
|
||||
|
||||
const game = {
|
||||
gameCode,
|
||||
teams: [{
|
||||
name: teamName,
|
||||
score: 0,
|
||||
players: []
|
||||
}],
|
||||
currentRound: 1,
|
||||
usedQuestions: [],
|
||||
status: 'waiting',
|
||||
createdAt: new Date()
|
||||
};
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
gameCode,
|
||||
game
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Проверить существование игры
|
||||
router.get('/:gameCode', (req, res) => {
|
||||
try {
|
||||
const { gameCode } = req.params;
|
||||
// Проверка будет в Socket.io, т.к. игры хранятся в памяти
|
||||
res.json({ exists: true });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user