From 8ebd3a1615e44fcb08609eaab14acb59dae411a2 Mon Sep 17 00:00:00 2001 From: Sea10wood Date: Sat, 17 Aug 2024 15:09:28 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20shooter=5Fscore=E3=82=92=E5=85=83?= =?UTF-8?q?=E3=81=ABresult=E3=81=B8=E3=81=AE=E9=81=B7=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 27 +++--- src/pages/result/index.tsx | 105 +++++++++++++----------- src/pages/shooter/index.tsx | 159 ++++++++++++++++++++---------------- 3 files changed, 162 insertions(+), 129 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d2b23a8..e1f9123 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,18 +3,25 @@ import Home from "./pages/home"; import Result from "./pages/result"; import Shooter from "./pages/shooter"; import Yatai from "./pages/yatai"; +import { useState } from "react"; const AppRoutes = () => { - return ( - <> - - } /> - } /> - } /> - } /> - - - ); + const [score, setScore] = useState(0); + + return ( + + } /> + } + /> + } + /> + } /> + + ); }; export default AppRoutes; diff --git a/src/pages/result/index.tsx b/src/pages/result/index.tsx index aa90a4e..410b82e 100644 --- a/src/pages/result/index.tsx +++ b/src/pages/result/index.tsx @@ -1,55 +1,62 @@ -import GetImage from "../../components/GetImage"; import { DefaultButton } from "../../components/ui/Button"; +import GetImage from "../../components/GetImage"; import styles from "./index.module.css"; -function Result() { - const images = [ - "/drink/bottle0.webp", - "/drink/bottle1.webp", - "/drink/bottle2.webp", - "/drink/bottle3.webp", - ]; +type ResultProps = { + score: number; +}; + +const Result = ({ score }: ResultProps) => { + const images = [ + "/drink/bottle0.webp", + "/drink/bottle1.webp", + "/drink/bottle2.webp", + "/drink/bottle3.webp", + ]; + + + const image = images[score] ; - return ( -
-
-

結果発表!

-
-
- -
-
- 背景にばーちゃるなつまつりのロゴ -
-
-

Bottle Get!

-
-
- - - Xで共有する - - -
-
-

また遊びにきてや〜

-
-
- ); -} + return ( +
+
+

結果発表!

+
+
+ +
+
+ 背景にばーちゃるなつまつりのロゴ +
+
+

${score}本倒した!

+
+
+ + + Xで共有する + + +
+
+

また遊びにきてや〜

+
+
+ ); +}; export default Result; diff --git a/src/pages/shooter/index.tsx b/src/pages/shooter/index.tsx index 2697422..fb9b42f 100644 --- a/src/pages/shooter/index.tsx +++ b/src/pages/shooter/index.tsx @@ -1,88 +1,107 @@ -import { type KeyboardEventHandler, useState } from "react"; +import { type KeyboardEventHandler, useEffect, useState } from "react"; import { DefaultButton } from "../../components/ui/Button"; import { Modal } from "../../components/ui/Modal"; import { ShooterButton } from "../../components/ui/ShooterButton"; import style from "./index.module.css"; -function Shooter() { - const [isOpen, setIsOpen] = useState(true); +type ShooterProps = { + setScore: (score: number) => void; +}; + +const Shooter = ({ setScore }: ShooterProps) => { + const [isOpen, setIsOpen] = useState(true); + const [score, setLocalScore] = useState(0); + + const initialImages = [ + "/2D_material/cork.webp", + "/2D_material/cork.webp", + "/2D_material/cork.webp", + ]; + const [images, setImages] = useState(initialImages); - const initialImages = [ - "/2D_material/cork.webp", - "/2D_material/cork.webp", - "/2D_material/cork.webp", - ]; + // Update score only when it changes + useEffect(() => { + setScore(score); + }, [score, setScore]); - const [images, setImages] = useState(initialImages); + const handleClick = () => { + const audio = new Audio("/sound/cork_sound.mp3"); + audio.play().catch((error) => { + console.error("オーディオの音が出なかった", error); + }); - const handleClick = () => { - const audio = new Audio("/sound/cork_sound.mp3"); - audio - .play() - .then(() => { - setImages((prevImages) => prevImages.slice(1)); - }) - .catch((error) => { - console.error("オーディオの音が出なかった", error); - setImages((prevImages) => prevImages.slice(1)); - }); - }; + setImages((prevImages) => { + if (prevImages.length > 0) { + return prevImages.slice(1); + } + return prevImages; + }); - const handleKeyUp: KeyboardEventHandler = (event) => { - if (event.key === "Enter" || event.key === " ") { - handleClick(); - } - }; + setLocalScore((prevScore) => { + const newScore = prevScore + 1; // Increment score or adjust as needed + return newScore; + }); + }; - return ( -
- setIsOpen(false)}> - - -
- -
-
- {images.map((src) => ( - コルクの残量を表示しています - ))} -
-
- ); -} + const handleKeyUp: KeyboardEventHandler = (event) => { + if (event.key === "Enter" || event.key === " ") { + handleClick(); + } + }; + + return ( +
+ setIsOpen(false)}> + + +
+ +
+
+ {images.length > 0 ? ( + images.map((src) => ( + コルクの残量を表示しています + )) + ) : ( +

コルクがなくなりました!

+ )} +
+
+ ); +}; type ModalContentProps = { - setIsOpen: (isOpen: boolean) => void; + setIsOpen: (isOpen: boolean) => void; }; const ModalContent: React.FC = ({ setIsOpen }) => { - return ( -
- スマホを画面に向かって垂直におく図 -
-

- スマホを画面に向かって -
- 垂直に机の上に置いてね -

-
-
- setIsOpen(false)} - > - 置いたよ! - -
-
- ); + return ( +
+ スマホを画面に向かって垂直におく図 +
+

+ スマホを画面に向かって +
+ 垂直に机の上に置いてね +

+
+
+ setIsOpen(false)} + > + 置いたよ! + +
+
+ ); }; export default Shooter;