Skip to content

Commit

Permalink
feat: Added current action displaying backend
Browse files Browse the repository at this point in the history
- Added actions
- Deleted some unnecessary stuff
Issue #17 done;
  • Loading branch information
KasparMakke committed Dec 1, 2024
1 parent dbb6dd9 commit 64b15f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
9 changes: 9 additions & 0 deletions app/backend/game/gameLogicScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const lives = Array(players.length).fill(3);
//jälgib ka kes tegi viimase bluffi indeksi
export const activeBluff = {diceValue:1, diceAmount:1, playerIndex:0};

export const actions = {
nil: "NIL",
passTurn: "PASSTURN",
challange: "CHALLANGE",
bullseye: "BULLSEYE"
}
export const currentAction = actions.nil;

//impordin serverist rooms objectid,
//et kõik sellege seotud funktsioonid töötaksid
import { rooms } from '../server'
Expand All @@ -30,6 +38,7 @@ export function handleGameStart(roomCode) {
rooms[roomCode].dice = handleDiceRolls(rooms[roomCode].dice);
//Mängu alguse turni seadmine
rooms[roomCode].turns = handleTurns(rooms[roomCode].turns, roomCode);
currentAction = actions.nil;
}

//Muudab kelle turn on olenevat sellest kelle turn prg on
Expand Down
32 changes: 24 additions & 8 deletions app/backend/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { handleGameStart,handleTurns ,handlePlayerDeath,handleDiceCheck, handleDiceBidSubmit, handleDiceRolls, checkGameOver,handlePlayerDeath} from './gameLogicScript.js';
import { currentAction } from './game/gameLogicScripts.js';
import {
handleGameStart,
handleTurns,
handlePlayerDeath,
handleDiceCheck,
handleDiceBidSubmit,
handleDiceRolls,
checkGameOver,
handlePlayerDeath,
actions } from './gameLogicScript.js';
const { Server } = require("socket.io");

const io = new Server(3030, {
Expand All @@ -12,10 +22,6 @@ export let rooms = {};
io.on("connection", (socket) => {
console.log("serveriga ühendatud: " + socket.id);

// socket.on("test-event", (number, string, obj) => {
// console.log(number, string, obj)
// })

// RUUMI LOOMINE
socket.on("create-room", (roomCode, hostName) => {
if (rooms[roomCode]) {
Expand All @@ -37,7 +43,15 @@ io.on("connection", (socket) => {
turns: null,
dice: null,
lives: null,
activeBid: {diceValue: 1, diceAmount: 1, playerIndex: 0 }
activeBid: {diceValue: 1, diceAmount: 1, playerIndex: 0 },
actions: {
nil: "NIL",
updateBets: "UPDATEBETS",
passTurn: "PASSTURN",
challange: "CHALLANGE",
bullseye: "BULLSEYE"
},
currentAction: null
};

socket.join(roomCode);
Expand Down Expand Up @@ -105,6 +119,7 @@ io.on("connection", (socket) => {
socket.on("game-start", ({ roomCode }) =>{
handleGameStart(roomCode);

io.to(roomCode).emit("display-action", rooms[roomCode].currentAction.nil); // naitab hetkese inimese actionit
io.to(roomCode).emit("hide-all-dices"); // peidab koikide diceid
io.to(roomCode).emit("display-player-dices", socket.id); // naitab ainult playeri elusi
io.to(roomCode).emit("display-hearts", rooms[roomCode].lives); // naitab koikide inimeste elusi
Expand All @@ -116,13 +131,14 @@ io.on("connection", (socket) => {

handleDiceBidSubmit(roomCode, diceAmount, diceValue);

io.to(roomCode).emit("display-action", rooms[roomCode].currentAction.passTurn); // naitab hetkese inimese actionit
io.to(roomCode).emit("display-current-bid", rooms[roomCode].activeBid); // naitab hetkest bidi
});

socket.on("challange", (roomCode) => {
console.log("Challanged!")

io.to(roomCode).emit("display-action"); // naitab hetkese inimese actionit
io.to(roomCode).emit("display-action", rooms[roomCode].currentAction.challange); // naitab hetkese inimese actionit
io.to(roomCode).emit("display-all-dices", rooms[roomCode].dice); // naitab koikide inimeste taringuid

handleDiceCheck(roomCode);
Expand All @@ -135,7 +151,7 @@ io.on("connection", (socket) => {
socket.on("check-bid", ({ response, roomCode }) => {
console.log("Bullseye!")

io.to(roomCode).emit("display-action"); // naitab hetkese inimese actionit
io.to(roomCode).emit("display-action", rooms[roomCode].currentAction.bullseye); // naitab hetkese inimese actionit
io.to(roomCode).emit("display-all-dices", rooms[roomCode].dice); // naitab koikide inimeste taringuid

handleDiceCheck(response, roomCode);
Expand Down
2 changes: 1 addition & 1 deletion components/pages/gamepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ socket.on("display-current-bid", (activeBid) => {
});

// display current action
socket.on("display-current-bid", () => {
socket.on("display-action", (action) => {

});

Expand Down

0 comments on commit 64b15f5

Please sign in to comment.