diff --git a/Domains/Frontend/MiniProjects/TIC-TAC-TOE/README.md b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/README.md new file mode 100644 index 00000000..a7705f2b --- /dev/null +++ b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/README.md @@ -0,0 +1,29 @@ +# đšī¸ Tic-Tac-Toe Game (Mini-Project) + +**Contributor:** shravanidorle + +## Description + +This project is a classic, fully functional **Tic-Tac-Toe** game designed for two players. It is built entirely using **HTML, CSS, and vanilla JavaScript**, demonstrating core front-end logic and DOM manipulation skills. + +The game features: + +- A clear $3 \times 3$ grid interface. +- Turn-based player logic (Player O vs. Player X). +- Win detection across rows, columns, and diagonals. +- A dedicated display message to announce the winner or a draw. +- **"New Game"** and **"Reset Game"** buttons to restart the game state. + +This is an excellent example of a complete, interactive mini-project suitable for the Frontend domain. + +## đ Technologies Used + +- **HTML5** (Structure) +- **CSS3** (Styling, including custom Google Fonts) +- **JavaScript (Vanilla)** (Core game logic, turn management, and win checking) + +## đ ī¸ How to Run + +1. **Clone the repository.** +2. Navigate to this project folder: `Domains/Frontend/MiniProjects/TicTacToe` (or your chosen project folder name). +3. Open the **`index.html`** file directly in any web browser. No local server or dependencies are required. diff --git a/Domains/Frontend/MiniProjects/TIC-TAC-TOE/app.js b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/app.js new file mode 100644 index 00000000..3f640af3 --- /dev/null +++ b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/app.js @@ -0,0 +1,100 @@ +let box=document.querySelectorAll(".box"); +let reset=document.querySelector("#reset"); +let newgame=document.querySelector("#btn"); +let msgCon=document.querySelector(".msg-container"); +let msg=document.querySelector("#winner"); +let main=document.querySelector("main"); + +let turnO=true; + +const win=[ + [0,1,2], + [0,3,6], + [0,4,8], + [1,4,7], + [2,5,8], + [2,4,6], + [3,4,5], + [6,7,8] +]; + +const resetGame=()=>{ + turnO=true + enableBoxes(); + msgCon.classList.add("hide") +} + +const enableBoxes=()=>{ + for (let i of box){ + i.disabled=false; + i.innerHTML=""; + i.classList.remove("x", "o"); + } +} + +box.forEach((box)=>{ + box.addEventListener("click",function(){ + if(turnO===true){ + box.classList.add("o"); + box.innerHTML="O"; + turnO=false; + }else{ + box.classList.add("x"); + box.innerHTML="X"; + turnO=true; + } + box.disabled=true; + + checkWinner(); + }) +}) + +const disableBoxes=()=>{ + box.forEach((box)=>{ + box.disabled=true; + }) +} + +const showwinner=(winner)=>{ + msg.innerHTML=`Player ${winner} is winner !`; + msgCon.classList.remove("hide") + disableBoxes(); +} + + +const checkWinner =()=>{ + let filledBoxes = 0; + let winnerFound = false; + for (let i of win) + { + let val1=box[i[0]].innerHTML; + let val2=box[i[1]].innerHTML; + let val3=box[i[2]].innerHTML; + if (val1!="" && val2!="" && val3!="") + { + if(val1===val2 && val2===val3) + { + document.querySelector("h1").innerHTML=`Player ${val1} wins !`; + showwinner(val1) + winnerFound = true; + break; + } + } + } + + box.forEach((box) => { + if (box.innerHTML !== "") { + filledBoxes++; + } + }); + + if (filledBoxes === 9 && !winnerFound) { + document.querySelector("h1").innerHTML = "It's a draw!"; + msg.innerHTML = "It's a draw!"; + msgCon.classList.remove("hide"); + } +}; + + +newgame.addEventListener("click",resetGame); +reset.addEventListener("click",resetGame) \ No newline at end of file diff --git a/Domains/Frontend/MiniProjects/TIC-TAC-TOE/index.html b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/index.html new file mode 100644 index 00000000..7d8742e8 --- /dev/null +++ b/Domains/Frontend/MiniProjects/TIC-TAC-TOE/index.html @@ -0,0 +1,37 @@ + + +
+ + +