Changeset aac3b2b
- Timestamp:
- 07/07/22 23:53:57 (2 years ago)
- Branches:
- main
- Children:
- 95ce58b
- Parents:
- 189cd8f
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
components/poker/sections/Messages.jsx
r189cd8f raac3b2b 24 24 return ( 25 25 <div className="pokerMessagesContainer"> 26 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length === 1 && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} with a {playerState.pokerGame.table.winners[0]?.hand?.hand} combination! Congratulations.</p> } 27 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length > 1 && <p>Game over - {playerState.pokerGame.table.winners.map(e=>e.displayName).join(", ")} drew!</p> } 28 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && <p>New game will start soon.</p> } 26 { playerState.pokerGame.table.ended && playerState.pokerGame.table.onlyOnePlayerLeft && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} because everyone else folded! Congratulations.</p> } 27 { playerState.pokerGame.table.ended && !playerState.pokerGame.table.onlyOnePlayerLeft && playerState.pokerGame.table.winners.length === 1 && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} with a {playerState.pokerGame.table.winners[0]?.hand?.hand} combination! Congratulations.</p> } 28 { playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length > 1 && <p>Game over - {playerState.pokerGame.table.winners.map(e=>e.displayName).join(", ")} drew!</p> } 29 { playerState.pokerGame.table.ended && <p>New game will start soon.</p> } 29 30 30 31 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Round {playerState.pokerGame.table.round}/4{roundMessage}</p> } 31 { !playerState.pokerGame.table.started && <p>Waiting for coordinator {playerState.pokerGame.table.creator} to start the game.</p> }32 { !playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Waiting for coordinator {playerState.pokerGame.table.creator} to start the game.</p> } 32 33 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{turnMessage}</p> } 33 34 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{callMessage}</p> } -
components/poker/sections/PickATable.jsx
r189cd8f raac3b2b 49 49 <h3>Pick a table:</h3> 50 50 <div onClick={(e) => joinATable(e)}> 51 {playerState.pokerGame.tables. map(table => (51 {playerState.pokerGame.tables.filter(table=>table.started===false).map(table => ( 52 52 <div data-table={table.id} key={table.id}> 53 53 <p data-table={table.id}>Table name: {table.name}</p> 54 54 <p data-table={table.id}>Creator: {table.creator}</p> 55 <p data-table={table.id}>Players: {table.players. length}/8</p>55 <p data-table={table.id}>Players: {table.players.filter(e=>e.isGhost===false).length}/8</p> 56 56 <p data-table={table.id}>Join</p> 57 57 </div> -
components/poker/sections/PlayButtons.jsx
r189cd8f raac3b2b 60 60 return ( 61 61 <div className="pokerPlayButtonsContainer"> 62 {!playerState.pokerGame.table.started && playerState.pokerGame.player.isCoordinator && playerState.pokerGame.player.isSatDown && <button className="secondaryButton" onClick={() => startGame()}>Start game</button>}62 {!playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && playerState.pokerGame.player.isCoordinator && playerState.pokerGame.player.isSatDown && <button className="secondaryButton" onClick={() => startGame()}>Start game</button>} 63 63 {!playerState.pokerGame.table.started && !playerState.pokerGame.player.isSatDown && <button className="secondaryButton" onClick={() => sitDown()}>Take a seat</button>} 64 64 </div> -
pages/api/poker/index.js
r189cd8f raac3b2b 47 47 }, 48 48 }], 49 onlyOnePlayerLeft: false, 49 50 winners: [], 50 51 splitWinners: false, … … 281 282 const { success, table } = getTableAndPlayer(req.query.session_id) 282 283 283 if (success && !table.started ) {284 if (success && !table.started && !table.ended && table.players.filter(e=>e.isSatDown===true).length >= 2) { 284 285 table.players.forEach(player => { 285 286 axios.get(`${process.env.HOME_URL}/api/postgre/?action=check_if_logged_in&session_id=${player.id}`).then(postgreRes => { … … 342 343 player.isFolded = true; 343 344 344 if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) { 345 setNextPlayerIdx(table.id); 345 if (table.started) { 346 if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) { 347 setNextPlayerIdx(table.id); 348 } 349 } 350 else { 351 table.players = table.players.filter(e=>e.isGhost === false); 346 352 } 347 353 } -
pages/api/poker/tableSpecific.js
r189cd8f raac3b2b 62 62 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 63 63 64 if (tables[tableIdx] !== undefined) { 65 const table = tables[tableIdx]; 64 if (tables[tableIdx] !== undefined && !tables[tableIdx].ended) { 65 const table = tables[tableIdx]; 66 67 const remainingPlayers = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false); 68 if (remainingPlayers.length === 1) { 69 setWinnerDirect(table.id, remainingPlayers[0]); 70 71 return ; 72 } 73 74 const remainingPlayersWithCredits = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false).filter(e=>e.isFolded===false).filter(e=>e.credits > 0); 75 if (remainingPlayersWithCredits.length === 1) { 76 progressRoundTillTheEnd(table.id); 77 78 return ; 79 } 66 80 67 81 if (table.turnTimeout !== null) clearTimeout(table.turnTimeout); … … 83 97 if (table.players[table.turnIdx] !== undefined) { 84 98 table.players[table.turnIdx].isFolded = true; 85 99 86 100 setNextPlayerIdx(table.id); 87 101 } … … 136 150 table.ended = false; 137 151 table.round = 0; 138 table.turnIdx = 0;152 table.turnIdx = -1; 139 153 table.turnTimeout = null; 140 154 table.pot = 0; … … 143 157 table.deck = [...deck]; 144 158 145 table.players = table.players.filter(e=>e.isGhost === false); 146 table.players = table.players.filter(e=>e.credits >= 20); 159 table.players = table.players.filter(e=>e.isGhost === false).filter(e=>e.credits >= 20); 147 160 148 161 table.players.forEach(player => { … … 157 170 } 158 171 }) 172 173 table.onlyOnePlayerLeft = false; 159 174 table.winners = []; 160 175 table.splitWinners = false; … … 168 183 if (tables[tableIdx] !== undefined) { 169 184 const table = tables[tableIdx]; 170 171 const satDownPlayers = table.players.filter(e => e.isSatDown === true);172 const satDownCount = satDownPlayers.length;173 185 174 186 table.players.forEach(player => { … … 212 224 } 213 225 226 export function setWinnerDirect(tableId, player) { 227 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 228 229 if (tables[tableIdx] !== undefined) { 230 const table = tables[tableIdx]; 231 232 table.turnIdx = -1; 233 table.started = false; 234 table.ended = true; 235 236 table.onlyOnePlayerLeft = true; 237 table.winners = [player]; 238 239 giveMoneyToTheWinners(table.id); 240 } 241 } 242 214 243 export function setWinner(tableId) { 215 244 const tableIdx = tables.map(e=>e.id).indexOf(tableId); … … 259 288 } 260 289 290 export function progressRoundTillTheEnd(tableId) { 291 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 292 293 if (tables[tableIdx] !== undefined) { 294 const table = tables[tableIdx]; 295 296 while (table.round < 4) { 297 table.round++; 298 getCardsOnTable(table.id); 299 } 300 301 table.started = false; 302 table.ended = true; 303 if (table.ended && table.winners.length === 0) { 304 setWinner(table.id); 305 } 306 } 307 } 308 261 309 export function progressRoundIfNeeded(tableId) { 262 310 const tableIdx = tables.map(e=>e.id).indexOf(tableId); … … 277 325 } 278 326 else { 327 table.started = false; 279 328 table.ended = true; 280 329 } -
pages/api/postgre/index.js
r189cd8f raac3b2b 413 413 // Already logged in 414 414 res.json({ 415 success: false, 416 message: 'You are already logged in', 415 success: true, 416 message: 'Login successful', 417 session: session, 417 418 }) 418 419 }
Note:
See TracChangeset
for help on using the changeset viewer.