commit
7c8cc11068
@ -65,16 +65,18 @@ io.on('connection', socket => {
|
||||
});
|
||||
|
||||
socket.on('new message', function (data) {
|
||||
if (gameState[socket.room] !== undefined && addedUser) {
|
||||
socket.broadcast.to(socket.room).emit('new message', {
|
||||
username: socket.username,
|
||||
message: data
|
||||
});
|
||||
|
||||
generate_log_message(socket.room, socket.username, "MESSAGE", data);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
if (addedUser) {
|
||||
if (gameState[socket.room] !== undefined && addedUser) {
|
||||
socket.broadcast.to(socket.room).emit('user left', socket.username);
|
||||
let index = -1;
|
||||
for (let i = 0; i < gameState[socket.room].players.length; i++) {
|
||||
@ -102,7 +104,7 @@ io.on('connection', socket => {
|
||||
|
||||
// Game
|
||||
socket.on('roll dice', function () {
|
||||
|
||||
if (gameState[socket.room] !== undefined && addedUser) {
|
||||
if (gameState[socket.room].players[gameState[socket.room].whosNext].socketUsername === socket.username) {
|
||||
gameState[socket.room].started = true;
|
||||
let sides = 3;
|
||||
@ -114,9 +116,11 @@ io.on('connection', socket => {
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('get card', function (difficulty) {
|
||||
if (gameState[socket.room] !== undefined && addedUser) {
|
||||
if (gameState[socket.room].players[gameState[socket.room].whosNext].socketUsername === socket.username) {
|
||||
io.in(socket.room).emit('card', {'username': socket.username, 'card': getRandomCard(difficulty)});
|
||||
|
||||
@ -124,12 +128,15 @@ io.on('connection', socket => {
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('card finished', function (difficulty, answerIsCorrect) {
|
||||
if (gameState[socket.room] !== undefined && addedUser) {
|
||||
if (answerIsCorrect) gameState[socket.room].players[gameState[socket.room].whosNext].move(difficulty);
|
||||
io.in(socket.room).emit('card destroyed');
|
||||
gameState[socket.room].finish_turn();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user