summaryrefslogtreecommitdiff
path: root/client/src/Mancala/StartGame.tsx
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2021-06-24 23:11:39 +0200
committerMike Vink <mike1994vink@gmail.com>2021-06-24 23:11:39 +0200
commit976ed2b105e80b257ebb724b3061400f37460041 (patch)
treebd04ac5d0a7978d6d8a4a5e2d862bf574314f2f8 /client/src/Mancala/StartGame.tsx
parent3906fcf3d702f13da79c797c91a2dd32d874af49 (diff)
mega commit
Diffstat (limited to 'client/src/Mancala/StartGame.tsx')
-rw-r--r--client/src/Mancala/StartGame.tsx45
1 files changed, 27 insertions, 18 deletions
diff --git a/client/src/Mancala/StartGame.tsx b/client/src/Mancala/StartGame.tsx
index 9d5be2c..4cf8d94 100644
--- a/client/src/Mancala/StartGame.tsx
+++ b/client/src/Mancala/StartGame.tsx
@@ -1,15 +1,17 @@
import React, { useState } from "react";
import type { GameState } from "../gameState";
import "./StartGame.css";
+import { Play } from "./Play"
type StartGameProps = {
+ gameState: GameState | undefined;
setGameState(newGameState: GameState): void;
}
/**
* Allows the players to enter their name. A name is required for both players. They can't have the same names.
*/
-export function StartGame({ setGameState }: StartGameProps) {
+export function StartGame({gameState, setGameState }: StartGameProps) {
const [errorMessage, setErrorMessage] = useState("");
const [playerOne, setPlayerOne] = useState("");
@@ -52,23 +54,30 @@ export function StartGame({ setGameState }: StartGameProps) {
}
}
- return (
- <form onSubmit={(e) => tryStartGame(e)}>
- <input value={playerOne}
- placeholder="Player 1 name"
- onChange={(e) => setPlayerOne(e.target.value)}
- />
+ if (localStorage.getItem("state") !== null) {
+ var state = localStorage.getItem("state");
+ const gameState = JSON.parse(state as string);
+ setGameState(gameState);
+ return <Play gameState={gameState} setGameState={setGameState} />
+ } else {
+ return (
+ <form onSubmit={(e) => tryStartGame(e)}>
+ <input value={playerOne}
+ placeholder="Player 1 name"
+ onChange={(e) => setPlayerOne(e.target.value)}
+ />
- <input value={playerTwo}
- placeholder="Player 2 name"
- onChange={(e) => setPlayerTwo(e.target.value)}
- />
+ <input value={playerTwo}
+ placeholder="Player 2 name"
+ onChange={(e) => setPlayerTwo(e.target.value)}
+ />
- <p className="errorMessage">{errorMessage}</p>
+ <p className="errorMessage">{errorMessage}</p>
- <button className="startGameButton" type="submit">
- Play Mancala!
- </button>
- </form>
- )
-} \ No newline at end of file
+ <button className="startGameButton" type="submit">
+ Play Mancala!
+ </button>
+ </form>
+ )
+ }
+}