Finish game
only responsive left
This commit is contained in:
parent
8a839555c6
commit
b1259b1f3d
1 changed files with 35 additions and 9 deletions
44
src/game.jsx
44
src/game.jsx
|
@ -86,7 +86,7 @@ export default ({ players }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const [grid, updateGrid] = useImmer(Array(9).fill(""));
|
const [grid, updateGrid] = useImmer(Array(9).fill(""));
|
||||||
const [score, updateScore] = useImmer(initialScore);
|
const [scores, updateScores] = useImmer(initialScore);
|
||||||
|
|
||||||
const [restartModal, setRestartModal] = useState(false);
|
const [restartModal, setRestartModal] = useState(false);
|
||||||
const [roundModal, setRoundModal] = useState(false);
|
const [roundModal, setRoundModal] = useState(false);
|
||||||
|
@ -99,7 +99,8 @@ export default ({ players }) => {
|
||||||
const winner = winningCombo.length > 0 ? grid[winningCombo[0]] : null;
|
const winner = winningCombo.length > 0 ? grid[winningCombo[0]] : null;
|
||||||
|
|
||||||
const gridFull = !grid.some((s) => s == "");
|
const gridFull = !grid.some((s) => s == "");
|
||||||
const roundOver = winner || gridFull;
|
const roundOver = gridFull || winner;
|
||||||
|
const tied = gridFull && !winner;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (roundOver) {
|
if (roundOver) {
|
||||||
|
@ -127,7 +128,7 @@ export default ({ players }) => {
|
||||||
}, [grid]);
|
}, [grid]);
|
||||||
|
|
||||||
const nextRound = () => {
|
const nextRound = () => {
|
||||||
updateScore((score) => {
|
updateScores((score) => {
|
||||||
if (winner) {
|
if (winner) {
|
||||||
score[winner].value++;
|
score[winner].value++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,10 +179,10 @@ export default ({ players }) => {
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer className="center flex-row justify-between text-navy-700">
|
<footer className="center flex-row justify-between text-navy-700">
|
||||||
{Object.values(score).map((value) => (
|
{Object.values(scores).map((score) => (
|
||||||
<div className={`center h-20 w-36 rounded-2xl ${value.bg}`}>
|
<div className={`center h-20 w-36 rounded-2xl ${score.bg}`}>
|
||||||
<p className="text-base uppercase">{value.display}</p>
|
<p className="text-base uppercase">{score.display}</p>
|
||||||
<p className="text-h-m uppercase">{value.value}</p>
|
<p className="text-h-m uppercase">{score.value}</p>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</footer>
|
</footer>
|
||||||
|
@ -208,12 +209,37 @@ export default ({ players }) => {
|
||||||
</form>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal
|
<Modal
|
||||||
|
className="center"
|
||||||
isOpen={roundModal}
|
isOpen={roundModal}
|
||||||
className="space-y-8"
|
|
||||||
onClose={() => setRoundModal(false)}
|
onClose={() => setRoundModal(false)}
|
||||||
>
|
>
|
||||||
|
{(() => {
|
||||||
|
if (tied) {
|
||||||
|
return (
|
||||||
|
<h2 className="text-h-l uppercase text-silver-700">Round tied</h2>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const HeadingSymbol = winner == "X" ? Cross : Oval;
|
||||||
|
const headingColor =
|
||||||
|
winner == "X" ? "text-blue-700" : "text-yellow-700";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p className="text-h-xs text-silver-700">
|
||||||
|
{players[winner]} wins!
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
className={`mt-4 flex items-center space-x-6 ${headingColor}`}
|
||||||
|
>
|
||||||
|
<HeadingSymbol className="size-16" />
|
||||||
|
<h2 className="text-h-l uppercase">Takes the round</h2>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
<form
|
<form
|
||||||
className="center flex-row space-x-4 text-navy-700"
|
className="center mt-6 flex-row space-x-4 text-navy-700"
|
||||||
method="dialog"
|
method="dialog"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
|
Reference in a new issue