Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
console.log('Request Body:', req.body);
const { ballNumber, action, playerName } = req.body;
const game = await Game.findOne();
const player = await Player.findOne({ name: playerName });
const actualBallValue = game.BinOrWinBalls[parseInt(ballNumber) - 1];
const isBallChosen = game.binOrWinState.chosenBalls.some(ball => ball.number === ballNumber);
if (isBallChosen) {
return res.status(400).json({ message: 'Ball already chosen.' });
}
const winCount = game.jackpot.length;
const binCount = game.binOrWinState.chosenBalls.length - winCount;
if ((action === 'win' && winCount >= 5) || (action === 'bin' && binCount >= 5)) {
return res.status(400).json({ message: `Maximum balls chosen for ${action}.` });
}
game.binOrWinState.chosenBalls.push({ number: ballNumber, value: actualBallValue });
if (action === 'win') {
game.jackpot.push(actualBallValue);
if (actualBallValue === 'Killer') {
let sumBeforeKiller = 0;
for (let ball of game.jackpot.slice(0, -1)) {
sumBeforeKiller += Number(ball);
}
const newSumBeforeKiller = (sumBeforeKiller / 10).toFixed(2);
game.jackpot.pop();
game.jackpot.push(newSumBeforeKiller, actualBallValue);
}
}
const otherPlayer = await Player.findOne({ name: { $ne: playerName } });
game.binOrWinState.currentPlayer = otherPlayer.name;
await game.save();
// Compute the new jackpot total
await exports.computeJackpot(game); // Now passing the game object
const wss = websocket.getWss();
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({
type: 'ballActionTaken',
ballNumber: ballNumber,
action: action,
ballValue: actualBallValue,
jackpotTotal: game.finalJackpot // Send the updated jackpot total
}));
}
});
res.json({
message: `Ball # ${ballNumber} with the Value "${actualBallValue}" chosen for ${action}!`,
ballValue: actualBallValue,
jackpotTotal: game.finalJackpot // Include the jackpot total in the response
});
};
// Modified computeJackpot to just compute and update the jackpot without sending a response
exports.computeJackpot = async (game) => {
if (!game) {
game = await Game.findOne();
}
let total = 0;
let divideBy = 1;
for (let i = game.jackpot.length - 1; i >= 0; i--) {
const ball = game.jackpot[i];
if (ball === 'Killer') {
divideBy *= 10;
} else {
total += ball / divideBy;
}
}
game.finalJackpot = total;
await game.save();
};
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team