From e4b2992f969784cdafa4c5a48f62a90e78a33884 Mon Sep 17 00:00:00 2001
From: dhruvathakur <128789248+DhruvaPratapSingh@users.noreply.github.com>
Date: Wed, 22 Oct 2025 11:35:01 +0530
Subject: [PATCH 1/3] add racing game component and test
---
src/app/components/game/Racing.jsx | 69 +++++++++++++++++++++++++
src/app/components/game/Racing.test.jsx | 7 +++
src/app/components/page.jsx | 21 ++++++++
3 files changed, 97 insertions(+)
create mode 100644 src/app/components/game/Racing.jsx
create mode 100644 src/app/components/game/Racing.test.jsx
diff --git a/src/app/components/game/Racing.jsx b/src/app/components/game/Racing.jsx
new file mode 100644
index 0000000..5274aa2
--- /dev/null
+++ b/src/app/components/game/Racing.jsx
@@ -0,0 +1,69 @@
+import { useEffect, useState } from "react";
+
+export default function Racing() {
+ const [car1, setCar1] = useState(0);
+ const [car2, setCar2] = useState(0);
+ const [winner, setWinner] = useState("");
+ const [running, setRunning] = useState(false);
+
+ useEffect(() => {
+ if (!running) return;
+
+ const race = setInterval(() => {
+ setCar1((prev) => Math.min(prev + Math.random() * 8, 300));
+ setCar2((prev) => Math.min(prev + Math.random() * 8, 300));
+ }, 100);
+
+ return () => clearInterval(race);
+ }, [running]);
+
+ useEffect(() => {
+ if (car1 >= 300 || car2 >= 300) {
+ setRunning(false);
+ if (car1 > car2) setWinner("🚗 Car 1 Wins!");
+ else if (car2 > car1) setWinner("🏎️ Car 2 Wins!");
+ else setWinner("🤝 It’s a Tie!");
+ }
+ }, [car1, car2]);
+
+ const startRace = () => {
+ setCar1(0);
+ setCar2(0);
+ setWinner("");
+ setRunning(true);
+ };
+
+ return (
+
+
🏁 Simple Racing Game
+
+
+
+ {winner && (
+
+ {winner}
+
+ )}
+
+
+
+ );
+}
diff --git a/src/app/components/game/Racing.test.jsx b/src/app/components/game/Racing.test.jsx
new file mode 100644
index 0000000..fe2ea98
--- /dev/null
+++ b/src/app/components/game/Racing.test.jsx
@@ -0,0 +1,7 @@
+import { render, screen } from "@testing-library/react";
+import Racing from "./racing";
+
+test("renders racing component", () => {
+ render();
+ expect(screen.getByText("🏁 Simple Racing Game")).toBeInTheDocument();
+});
diff --git a/src/app/components/page.jsx b/src/app/components/page.jsx
index 7a84fdf..b15a4a4 100644
--- a/src/app/components/page.jsx
+++ b/src/app/components/page.jsx
@@ -69,6 +69,8 @@ import ALertManager from "./alert/ALertManager";
import Loader from "./loaders/Loader";
// form Input
+// game
+import Test from "./game/Racing"
import { DatePicker } from "./FormInput/DatePicker";
import { FileUpload } from "./FormInput/FileUpload";
import { FormValidation } from "./FormInput/FormValidation";
@@ -739,6 +741,25 @@ export default function Page() {
)}
+{/* Racing Section */}
+
+
+ {/* Glassy overlay */}
+
+
+ {/* Content */}
+
+
+ 🏁 Game Section
+
+
+
+
+
{/* Cards Section */}
{filteredComponents.cards && (
From 473587864b356ca9b02e0dbc5a9e5f59c36c7332 Mon Sep 17 00:00:00 2001
From: dhruvathakur <128789248+DhruvaPratapSingh@users.noreply.github.com>
Date: Wed, 22 Oct 2025 12:20:08 +0530
Subject: [PATCH 2/3] add racing game component and integrate into the main
page
---
src/app/components/game/Racing.jsx | 69 -------------------
src/app/components/game/Racing.test.jsx | 7 --
src/app/components/page.jsx | 6 +-
src/app/game/Racing.jsx | 91 +++++++++++++++++++++++++
src/app/game/page.jsx | 50 ++++++++++++++
src/app/pages/Navbar.jsx | 2 +
6 files changed, 146 insertions(+), 79 deletions(-)
delete mode 100644 src/app/components/game/Racing.jsx
delete mode 100644 src/app/components/game/Racing.test.jsx
create mode 100644 src/app/game/Racing.jsx
create mode 100644 src/app/game/page.jsx
diff --git a/src/app/components/game/Racing.jsx b/src/app/components/game/Racing.jsx
deleted file mode 100644
index 5274aa2..0000000
--- a/src/app/components/game/Racing.jsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { useEffect, useState } from "react";
-
-export default function Racing() {
- const [car1, setCar1] = useState(0);
- const [car2, setCar2] = useState(0);
- const [winner, setWinner] = useState("");
- const [running, setRunning] = useState(false);
-
- useEffect(() => {
- if (!running) return;
-
- const race = setInterval(() => {
- setCar1((prev) => Math.min(prev + Math.random() * 8, 300));
- setCar2((prev) => Math.min(prev + Math.random() * 8, 300));
- }, 100);
-
- return () => clearInterval(race);
- }, [running]);
-
- useEffect(() => {
- if (car1 >= 300 || car2 >= 300) {
- setRunning(false);
- if (car1 > car2) setWinner("🚗 Car 1 Wins!");
- else if (car2 > car1) setWinner("🏎️ Car 2 Wins!");
- else setWinner("🤝 It’s a Tie!");
- }
- }, [car1, car2]);
-
- const startRace = () => {
- setCar1(0);
- setCar2(0);
- setWinner("");
- setRunning(true);
- };
-
- return (
-
-
🏁 Simple Racing Game
-
-
-
- {winner && (
-
- {winner}
-
- )}
-
-
-
- );
-}
diff --git a/src/app/components/game/Racing.test.jsx b/src/app/components/game/Racing.test.jsx
deleted file mode 100644
index fe2ea98..0000000
--- a/src/app/components/game/Racing.test.jsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import { render, screen } from "@testing-library/react";
-import Racing from "./racing";
-
-test("renders racing component", () => {
- render();
- expect(screen.getByText("🏁 Simple Racing Game")).toBeInTheDocument();
-});
diff --git a/src/app/components/page.jsx b/src/app/components/page.jsx
index b15a4a4..d4b7007 100644
--- a/src/app/components/page.jsx
+++ b/src/app/components/page.jsx
@@ -69,8 +69,8 @@ import ALertManager from "./alert/ALertManager";
import Loader from "./loaders/Loader";
// form Input
-// game
-import Test from "./game/Racing"
+
+
import { DatePicker } from "./FormInput/DatePicker";
import { FileUpload } from "./FormInput/FileUpload";
import { FormValidation } from "./FormInput/FormValidation";
@@ -756,7 +756,7 @@ export default function Page() {
diff --git a/src/app/game/Racing.jsx b/src/app/game/Racing.jsx
new file mode 100644
index 0000000..174e7b6
--- /dev/null
+++ b/src/app/game/Racing.jsx
@@ -0,0 +1,91 @@
+"use client";
+import { useEffect, useState } from "react";
+
+export default function Racing() {
+ const [car1, setCar1] = useState(0);
+ const [car2, setCar2] = useState(0);
+ const [winner, setWinner] = useState("");
+ const [running, setRunning] = useState(false);
+
+ const trackLength = 600; // total horizontal distance in px
+
+ // Race movement
+ useEffect(() => {
+ if (!running) return;
+
+ const race = setInterval(() => {
+ setCar1((prev) => Math.min(prev + Math.random() * 15, trackLength));
+ setCar2((prev) => Math.min(prev + Math.random() * 15, trackLength));
+ }, 100);
+
+ return () => clearInterval(race);
+ }, [running]);
+
+ // Check winner
+ useEffect(() => {
+ if (car1 >= trackLength || car2 >= trackLength) {
+ setRunning(false);
+ if (car1 > car2) setWinner("🚗 Car 1 Wins!");
+ else if (car2 > car1) setWinner("🏎️ Car 2 Wins!");
+ else setWinner("🤝 It’s a Tie!");
+ }
+ }, [car1, car2]);
+
+ const startRace = () => {
+ setCar1(0);
+ setCar2(0);
+ setWinner("");
+ setRunning(true);
+ };
+
+ return (
+
+
🏁 Racing Track
+
+ {/* Track */}
+
+ {/* Road markings */}
+
+
+ {/* Finish Line */}
+
+
+ {/* Car 1 */}
+
+ 🚗
+
+
+ {/* Car 2 */}
+
+ 🏎️
+
+
+
+ {/* Winner Display */}
+ {winner &&
{winner}
}
+
+ {/* Start Button */}
+
+
+
+
+ );
+}
diff --git a/src/app/game/page.jsx b/src/app/game/page.jsx
new file mode 100644
index 0000000..847fa87
--- /dev/null
+++ b/src/app/game/page.jsx
@@ -0,0 +1,50 @@
+"use client";
+import { useState } from "react";
+import Racing from "./Racing"; // Import the Racing component
+
+export default function Page() {
+ const [searchTerm, setSearchTerm] = useState("");
+ const [filterType, setFilterType] = useState("all");
+
+ return (
+
+
+ {/* Hero Section */}
+
+
+
+ React UI Playground
+
+
+ Beautiful, modern & responsive component demo – interact with components and explore smooth animations.
+
+
+
+
+
+ {/* Racing Game Section */}
+
+
+
+ 🏁 Racing Game
+
+
+
+
+
+ {/* Placeholder Section */}
+
+
+
+ More Components Coming Soon...
+
+
+ Stay tuned for more interactive UI components, demos, and fun features.
+
+
+
+
+ );
+}
diff --git a/src/app/pages/Navbar.jsx b/src/app/pages/Navbar.jsx
index 751b0e3..6ad9083 100644
--- a/src/app/pages/Navbar.jsx
+++ b/src/app/pages/Navbar.jsx
@@ -12,8 +12,10 @@ const navLinks = [
{ href: "/contact", label: "Contact" },
{ href: "/components", label: "Components" },
{ href: "/playground", label: "🎮 Playground" },
+ { href: "/game", label: "🎮 Game" },
{ href: "/analytics", label: "Analytics" },
{ href: "/feedback", label: "Feedback" },
+ {href: "/racing", label: "🏁 Racing Game" },
];
const Navbar = () => {
From 74d96150325f8b1e2beae37921e03cd0d62e90d3 Mon Sep 17 00:00:00 2001
From: dhruvathakur <128789248+DhruvaPratapSingh@users.noreply.github.com>
Date: Wed, 22 Oct 2025 12:26:18 +0530
Subject: [PATCH 3/3] refactor Racing component for responsive track length and
UI adjustments
---
src/app/game/Racing.jsx | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/app/game/Racing.jsx b/src/app/game/Racing.jsx
index 174e7b6..bdbbe2b 100644
--- a/src/app/game/Racing.jsx
+++ b/src/app/game/Racing.jsx
@@ -7,7 +7,21 @@ export default function Racing() {
const [winner, setWinner] = useState("");
const [running, setRunning] = useState(false);
- const trackLength = 600; // total horizontal distance in px
+ const trackLengthDesktop = 600; // px for desktop
+ const trackLengthMobile = 300; // px for small screens
+
+ const [trackLength, setTrackLength] = useState(trackLengthDesktop);
+
+ // Update track length on resize
+ useEffect(() => {
+ const updateTrackLength = () => {
+ if (window.innerWidth < 768) setTrackLength(trackLengthMobile);
+ else setTrackLength(trackLengthDesktop);
+ };
+ updateTrackLength();
+ window.addEventListener("resize", updateTrackLength);
+ return () => window.removeEventListener("resize", updateTrackLength);
+ }, []);
// Race movement
useEffect(() => {
@@ -19,7 +33,7 @@ export default function Racing() {
}, 100);
return () => clearInterval(race);
- }, [running]);
+ }, [running, trackLength]);
// Check winner
useEffect(() => {
@@ -29,7 +43,7 @@ export default function Racing() {
else if (car2 > car1) setWinner("🏎️ Car 2 Wins!");
else setWinner("🤝 It’s a Tie!");
}
- }, [car1, car2]);
+ }, [car1, car2, trackLength]);
const startRace = () => {
setCar1(0);
@@ -39,20 +53,20 @@ export default function Racing() {
};
return (
-
-
🏁 Racing Track
+
+
🏁 Racing Track
{/* Track */}
-
+
{/* Road markings */}
{/* Finish Line */}
-
+
{/* Car 1 */}
🚗
@@ -60,7 +74,7 @@ export default function Racing() {
{/* Car 2 */}
🏎️
@@ -68,13 +82,13 @@ export default function Racing() {
{/* Winner Display */}
- {winner &&
{winner}
}
+ {winner &&
{winner}
}
{/* Start Button */}