From 87f9951aad3fe0b3d4378bdd5b45d192e527fd71 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 7 May 2021 13:21:19 -0500 Subject: [PATCH] Ready for alpha release --- back/src/Game.ts | 15 ++++------- front/pages/index.tsx | 58 ++++++++++++++----------------------------- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/back/src/Game.ts b/back/src/Game.ts index 15155fd..6dbe502 100644 --- a/back/src/Game.ts +++ b/back/src/Game.ts @@ -19,13 +19,10 @@ class Player { } sendGameState() { const i = this.game.players.indexOf(this); - const otherPlayers = []; - for (let j = 1; j < this.game.players.length; ++j) - otherPlayers.push(this.game.players[(i + j) % this.game.players.length]); this.client.socket.emit('gameState', { cards: this.cards, rank: this.rank, - players: otherPlayers.map((p: Player) => ({ + players: this.game.players.map((p: Player) => ({ username: p.client.username, numCards: p.cards.length, stackSize: p.stack.length, @@ -129,8 +126,7 @@ export default class Game { delete p.disconnectListener; (() => { p.stack = stack; - p.client.socket.disconnect(); - logSocket(p.client.socket, 'Bad cards argument on turn'); + return; })(); resolve(); }); @@ -180,7 +176,7 @@ export default class Game { if (this.players[selectedPlayer].stack.length > 0) { if (this.players[selectedPlayer].stack[0].suit === Suit.Diamonds || this.players[selectedPlayer].stack[0].suit === Suit.Hearts) this.phase = 3; // Red card - this.players[selectedPlayer].stack.splice(0); + this.players[selectedPlayer].stack.splice(0, 1); return; } p.client.socket.disconnect(); @@ -202,9 +198,8 @@ export default class Game { p.client.once('giveup', card => { delete p.disconnectListener; (() => { - p.cards.splice(card); // Remove card, may want to check if it is valid - p.client.socket.disconnect(); - logSocket(p.client.socket, 'Bad cards argument on turn'); + p.cards.splice(card, 1); + return; })(); resolve(); }); diff --git a/front/pages/index.tsx b/front/pages/index.tsx index ec118e6..c77fc5c 100644 --- a/front/pages/index.tsx +++ b/front/pages/index.tsx @@ -38,8 +38,6 @@ export default function Game() { const [gameState, setGameState] = useState(null); const [num, setNum] = useState(0); - const [stackSelected, setStackSelected] = useState([]); - const [cardSelected, setCardSelected] = useState([]); useEffect(() => { const socket = io(process.env.NEXT_PUBLIC_BACK_HOST!); @@ -64,8 +62,6 @@ export default function Game() { socket.on('gameState', (data: GameState) => { setGameState(data); - if (data.cards.length !== cardSelected.length) - setCardSelected(new Array(data.cards.length).fill(false)); }); socket.on('endGame', () => setGameState(null)); @@ -116,8 +112,6 @@ export default function Game() { ); } - const selectedStacks = [...Array(gameState.players.length).keys()].filter((_, i) => stackSelected[i]); - const selectedCards = gameState.cards.filter((_, i) => cardSelected[i]); if (gameState.phase === 0) { return ( <> @@ -219,24 +213,15 @@ export default function Game() {

Stacks:

{gameState.players.map((player, i) => ( ))} - ); @@ -256,26 +241,19 @@ export default function Game() {

Your cards:

{gameState.cards.map((card, i) => ( ))} - );