From 23968cba6949c517abba941e22e7487227fe5de3 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 6 May 2021 22:25:04 -0500 Subject: [PATCH] Finished implementing phase 1 --- front/pages/index.tsx | 144 ++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 53 deletions(-) diff --git a/front/pages/index.tsx b/front/pages/index.tsx index 389a3b0..92d967f 100644 --- a/front/pages/index.tsx +++ b/front/pages/index.tsx @@ -1,4 +1,4 @@ -import {canPlay, Card} from 'bsx-core'; +import {Card} from 'bsx-core'; import {useEffect, useState} from 'react'; import io from 'socket.io-client'; @@ -9,9 +9,10 @@ import LoginForm from '../components/LoginForm'; interface GameState { cards: Card[], players: {username: string, numCards: number, rank: number}[], - lastPlayed: Card[] | null, + lastPlayed: number, lastPlayedPlayer: string | null, playerTurn: string + phase: number } const rankStrs = ['', 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; @@ -30,6 +31,8 @@ export default function Game() { const [gameState, setGameState] = useState(null); const [cardSelected, setCardSelected] = useState([]); + const [num, setNum] = useState(0); + useEffect(() => { const socket = io(process.env.NEXT_PUBLIC_BACK_HOST!); setSocket(socket); @@ -97,7 +100,7 @@ export default function Game() { {username === roomHost && @@ -106,54 +109,89 @@ export default function Game() { ); } const selectedCards = gameState.cards.filter((_, i) => cardSelected[i]); - return ( - <> -
    - {gameState.players.map(p => ( -
  • - {p.username + (p.rank ? ` (Rank ${p.rank})` : '') + (p.numCards ? ` (${p.numCards} cards)` : '')} -
  • - ))} -
-
-

Last played:

- {gameState.lastPlayed ? ( - <> - {gameState.lastPlayed.map((card, i) => {rankStrs[card.rank]+' '+suitChars[card.suit]+'|'})} - {` by ${gameState.lastPlayedPlayer}`} - - ) : '(Nothing)'} -
- {`It's ${gameState.playerTurn}'s turn!`} -
-

Your cards:

- {gameState.cards.map((card, i) => ( - - ))} - - -
- - ); + if (gameState.phase === 0) { + return ( + <> +
    + {gameState.players.map(p => ( +
  • + {p.username + (p.rank ? ` (Rank ${p.rank})` : '') + (p.numCards ? ` (${p.numCards} cards)` : '')} +
  • + ))} +
+ + + + ); + } + else if (gameState.phase === 1) { + return ( + <> +
    + {gameState.players.map(p => ( +
  • + {p.username + (p.rank ? ` (Rank ${p.rank})` : '') + (p.numCards ? ` (${p.numCards} cards)` : '')} +
  • + ))} +
+
+

Last played:

+ {gameState.lastPlayed ? ( + <> + {gameState.lastPlayed} + {` by ${gameState.lastPlayedPlayer}`} + + ) : '(Nothing)'} +
+ {`It's ${gameState.playerTurn}'s turn!`} +
+

Your cards:

+ setNum(+e.target.value)} + /> + + +
+ + ); + } + else if (gameState.phase === 2) { + return ( + <> +
    + {gameState.players.map(p => ( +
  • + {p.username + (p.rank ? ` (Rank ${p.rank})` : '') + (p.numCards ? ` (${p.numCards} cards)` : '')} +
  • + ))} +
+ + ); + } + else { + return ( + <> +
    + {gameState.players.map(p => ( +
  • + {p.username + (p.rank ? ` (Rank ${p.rank})` : '') + (p.numCards ? ` (${p.numCards} cards)` : '')} +
  • + ))} +
+ + ); + } }