Show current power and add win/lose message

This commit is contained in:
snen 2021-09-30 22:33:20 -04:00
parent e2d00188f6
commit bbd7f606dc
3 changed files with 37 additions and 12 deletions

View File

@ -19,7 +19,7 @@ export default function BoardSlot(props: CardTokenProps): JSX.Element {
return ( return (
<button <button
type="button" type="button"
className={`board-slot${isSelected ? ' selected' : ''}`} className={`board-card${isSelected ? ' selected' : ''}`}
onClick={onSelect} onClick={onSelect}
disabled={disabled} disabled={disabled}
> >
@ -28,11 +28,14 @@ export default function BoardSlot(props: CardTokenProps): JSX.Element {
) )
} }
return ( return (
<div className="board-slot">
<CardToken <CardToken
onSelect={onSelect}
cardKey={card.type} cardKey={card.type}
onSelect={onSelect}
isSelected={isSelected} isSelected={isSelected}
disabled={disabled} disabled={disabled}
/> />
<span>{card.power}</span>
</div>
) )
} }

View File

@ -14,6 +14,9 @@ import {
type GameProps = GameHandle type GameProps = GameHandle
const GAME_STATUS_SENTINAL_WIN = 4
const GAME_STATUS_SCOURGE_WIN = 5
export default function Game(props: GameProps): JSX.Element { export default function Game(props: GameProps): JSX.Element {
const { const {
team, team,
@ -64,6 +67,13 @@ export default function Game(props: GameProps): JSX.Element {
const allyBoard = team === 1 ? board.sentinal : board.scourge const allyBoard = team === 1 ? board.sentinal : board.scourge
const isMyTurn = currentTurn === team const isMyTurn = currentTurn === team
const maybeIsGameWinner =
gameStatus === GAME_STATUS_SCOURGE_WIN || gameStatus === GAME_STATUS_SENTINAL_WIN ? (
team === 1
? gameStatus === GAME_STATUS_SENTINAL_WIN
: gameStatus === GAME_STATUS_SCOURGE_WIN
) : null
return ( return (
<div className="game-container"> <div className="game-container">
<div className="game-sidebar"> <div className="game-sidebar">
@ -72,11 +82,17 @@ export default function Game(props: GameProps): JSX.Element {
<p>Life: {enemyLife}</p> <p>Life: {enemyLife}</p>
<p>Deck: {enemyDeckSize}</p> <p>Deck: {enemyDeckSize}</p>
</div> </div>
{maybeIsGameWinner === null ? (
<div> <div>
<p>{isMyTurn ? 'My' : 'Enemy'} Turn</p> <p>{isMyTurn ? 'My' : 'Enemy'} Turn</p>
{isMyTurn && canDraw && <button type="button" onClick={startDraw}>Start Draw</button>} {isMyTurn && canDraw && <button type="button" onClick={startDraw}>Start Draw</button>}
{isMyTurn && hasDrawn && <button type="button" onClick={endTurn}>End Turn</button>} {isMyTurn && hasDrawn && <button type="button" onClick={endTurn}>End Turn</button>}
</div> </div>
) : (
<div>
{maybeIsGameWinner ? "You Lose!" : "You Win!"}
</div>
)}
<div className="player-info"> <div className="player-info">
<p>Life: {player.life}</p> <p>Life: {player.life}</p>
<p>Deck: {deckSize}</p> <p>Deck: {deckSize}</p>

View File

@ -196,6 +196,12 @@ h2 {
} }
.board-slot { .board-slot {
display: flex;
flex-direction: column;
align-items: center;
}
.board-card {
width: 5em; width: 5em;
height: 7em; height: 7em;
margin: 0 1em; margin: 0 1em;