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 ( - <> - -
-

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 ( + <> + + + + + ); + } + else if (gameState.phase === 1) { + return ( + <> + +
+

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 ( + <> + + + ); + } + else { + return ( + <> + + + ); + } }