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%); transform: translate(-50%, -50%);
text-align: center; text-align: center;
border-radius: 5px; border-radius: 5px;
font-size: 70px;
padding-top: 100px;
pointer-events: none; pointer-events: none;
opacity: 0; opacity: 0;
transition: opacity 0.5s; transition: opacity 0.5s;
} }
.result h1 {
font-size: 70px;
}
.result button {
font-size: 20px;
}
.result.won { .result.won {
background-color: #090; background-color: #090;
} }

View file

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