feat: Add new game button

This commit is contained in:
sigmasternchen 2024-09-20 22:12:31 +02:00
parent 749057040f
commit 92058e63a7
3 changed files with 21 additions and 4 deletions

View file

@ -130,13 +130,19 @@ body {
transform: translate(-50%, -50%);
text-align: center;
border-radius: 5px;
font-size: 70px;
padding-top: 100px;
pointer-events: none;
opacity: 0;
transition: opacity 0.5s;
}
.result h1 {
font-size: 70px;
}
.result button {
font-size: 20px;
}
.result.won {
background-color: #090;
}

View file

@ -6,6 +6,7 @@ import {CellState, sortCellStates} from "../model/CellState";
import {Field} from "./Field";
import {Keyboard} from "./Keyboard";
import {Toast} from "./Toast";
import {GameResult} from "./GameResult";
export const Game = ({wordLength, numberOfGuesses, correctWord, availableWords, reset}) => {
const [gameState, setGameState] = useState(GameState.Active);
@ -96,7 +97,7 @@ export const Game = ({wordLength, numberOfGuesses, correctWord, availableWords,
/>
<Keyboard enabled={gameState === GameState.Active} used={usedWithState} onKey={inputHandler}/>
<Toast message={message}/>
<div className={"result won " + (gameState === GameState.Won ? "show" : "")}>You won!</div>
<div className={"result lost " + (gameState === GameState.Lost ? "show" : "")}>You lost!</div>
<GameResult reset={resetHandler} show={gameState === GameState.Won} className={"won"} text={"You won!"} />
<GameResult reset={resetHandler} show={gameState === GameState.Lost} className={"lost"} text={"You lost!"} />
</div>
}

View file

@ -0,0 +1,10 @@
import React from "react";
export const GameResult = ({show, className, text, reset}) => {
return <div className={"result " + className + " " + (show ? "show" : "")}>
<h1>{text}</h1>
<button onClick={reset}>New Game</button>
</div>
}