fixed bug related to multi row puzzle, need to fix win condition now
This commit is contained in:
parent
f89489f46f
commit
f070396a3d
50
server.js
50
server.js
@ -188,18 +188,42 @@ function checkGuess(letter,gameStateObject) {
|
||||
}
|
||||
function checkSolvePuzzleGuess(guess,ws) {
|
||||
const room = rooms[ws.roomCode]
|
||||
if (guess.toUpperCase() != room.gameState.puzzles[room.gameState.puzzleLevel].answer.toUpperCase()) {
|
||||
console.log(guess.toUpperCase(),room.gameState.puzzles[room.gameState.puzzleLevel].answer.toUpperCase())
|
||||
//guess is wrong change turns
|
||||
console.log('guess is incorrect')
|
||||
changeTurn(room.gameState,ws)
|
||||
console.log(room.gameState)
|
||||
//check if the answer is an array first as we have to parse it differently if thats the case.
|
||||
if (!Array.isArray(room.gameState.puzzles[room.gameState.puzzleLevel].answer)) {
|
||||
if (guess.toUpperCase() != room.gameState.puzzles[room.gameState.puzzleLevel].answer.toUpperCase()) {
|
||||
console.log(guess.toUpperCase(),room.gameState.puzzles[room.gameState.puzzleLevel].answer.toUpperCase())
|
||||
//guess is wrong change turns
|
||||
console.log('guess is incorrect')
|
||||
changeTurn(room.gameState,ws)
|
||||
}
|
||||
else {
|
||||
console.log('guess i correct')
|
||||
//guessed correctly reward the user
|
||||
rewardUser(room.gameState,ws,true)
|
||||
loadNewPuzzle(room.gameState,ws)
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('guess i correct')
|
||||
//guessed correctly reward the user
|
||||
rewardUser(room.gameState,ws,true)
|
||||
loadNewPuzzle(room.gameState,ws)
|
||||
//its probably an array
|
||||
console.log(room.gameState.puzzles[room.gameState.puzzleLevel])
|
||||
let answer = room.gameState.puzzles[room.gameState.puzzleLevel].answer
|
||||
//convert and filter the answer into a string that can be compared seperated by spaces
|
||||
answer = answer.filter(word => word != '').join(' ')
|
||||
if (answer.toUpperCase() != guess.toUpperCase()) {
|
||||
console.log('wrong',guess.toUpperCase(),answer.toUpperCase())
|
||||
//wrong
|
||||
changeTurn(room.gameState,ws)
|
||||
}
|
||||
else {
|
||||
//correct
|
||||
console.log('correct.',guess.toUpperCase(),answer.toUpperCase())
|
||||
rewardUser(room.gameState,ws,true)
|
||||
loadNewPuzzle(room.gameState,ws)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
function announceWinner(gameStateObject,ws) {
|
||||
//find user with highest points.
|
||||
@ -221,7 +245,7 @@ function rewardUser(gameStateObject,ws,puzzleSolved = false) {
|
||||
const room = rooms[ws.roomCode]
|
||||
//find the current player
|
||||
let currentUserTurn = gameStateObject.players[gameStateObject.turn]
|
||||
currentUserTurn.win++
|
||||
currentUserTurn.wins++
|
||||
gameStateObject.puzzleLevel++
|
||||
if (puzzleSolved) {
|
||||
currentUserTurn.points = currentUserTurn.points*3
|
||||
@ -229,6 +253,7 @@ function rewardUser(gameStateObject,ws,puzzleSolved = false) {
|
||||
}
|
||||
if (gameStateObject.puzzleLevel == gameStateObject.puzzles.length-1) {
|
||||
announceWinner(gameStateObject,ws)
|
||||
return
|
||||
}
|
||||
room.clients.forEach((client) => {
|
||||
client.send(JSON.stringify({
|
||||
@ -438,7 +463,7 @@ wss.on('connection', (ws) => {
|
||||
}
|
||||
if (room && room.leader === ws) {
|
||||
room.clients.forEach((client) => {
|
||||
console.log(client.id)
|
||||
console.log(client.identifierToken)
|
||||
client.send(JSON.stringify({
|
||||
type: 'game_started',
|
||||
roomCode: ws.roomCode,
|
||||
@ -472,6 +497,9 @@ wss.on('connection', (ws) => {
|
||||
|
||||
if (spinResult != ['lose a turn', 'spin again', 'Bankrupt'].indexOf(spinResult)) {
|
||||
room.gameState.turnState = 'guess'
|
||||
room.gameState.players = room.gameState.players.map((player) => {
|
||||
return player.id == ws.identifierToken ? {...player, points:parseInt(spinResult)} : player
|
||||
})
|
||||
}
|
||||
if (spinResult == 'Bankrupt') {
|
||||
room.gameState.players = room.gameState.players.map((player) => {
|
||||
|
Loading…
Reference in New Issue
Block a user