diff --git a/src/App.jsx b/src/App.jsx
index 62b11d4..e29daf2 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -19,6 +19,7 @@ import TabTest from "./pages/tree-view/custom-tabs/Tab-test";
import { ModalPopup } from "./pages/CustomModalPopup/ModalPopup";
import { GithubProfileFinder } from "./pages/GithubProfileFinder/GithubProfileFinder";
import { SearchAutoComplete } from "./pages/SearchAutoComplete/SearchAutoComplete";
+import { TicTacToe } from "./pages/TicTacToe";
function App() {
return (
@@ -47,15 +48,20 @@ function App() {
{/* generate QR code */}
this page under{" "}
{
+ const [squares, setSquares] = useState(Array(9).fill(""));
+ const [isXTurn, setIsXTurn] = useState(true);
+ const [winner, setWinner] = useState(null);
+ const [isDraw, setIsDraw] = useState(false);
+
+ function handleClick(currentSquare) {
+ if (winner || squares[currentSquare] || isDraw) return;
+
+ let cpySquares = [...squares];
+ cpySquares[currentSquare] = isXTurn ? "X" : "O";
+ setIsXTurn(!isXTurn);
+ setSquares(cpySquares);
+
+ const gameWinner = checkWinner(cpySquares);
+ if (gameWinner) {
+ setWinner(gameWinner);
+ } else if (!cpySquares.includes("")) {
+ // Check for draw if all squares are filled
+ setIsDraw(true);
+ }
+ }
+
+ function checkWinner(board) {
+ // Check rows
+ for (let i = 0; i < 3; i++) {
+ if (
+ board[i * 3] !== "" &&
+ board[i * 3] === board[i * 3 + 1] &&
+ board[i * 3] === board[i * 3 + 2]
+ ) {
+ return board[i * 3];
+ }
+ console.log(board[i * 3 + 1]);
+ }
+
+ // Check columns
+ for (let i = 0; i < 3; i++) {
+ if (
+ board[i] !== "" &&
+ board[i] === board[i + 3] &&
+ board[i] === board[i + 6]
+ ) {
+ return board[i];
+ }
+ }
+
+ // Check diagonals
+ if (board[0] !== "" && board[0] === board[4] && board[0] === board[8]) {
+ return board[0];
+ }
+ if (board[2] !== "" && board[2] === board[4] && board[2] === board[6]) {
+ return board[2];
+ }
+
+ return null;
+ }
+
+ function handleRestart() {
+ setIsXTurn(true);
+ setSquares(Array(9).fill(""));
+ setWinner(null);
+ setIsDraw(false);
+ }
+
+ return (
+