-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cae40cb
commit d49dc48
Showing
14 changed files
with
206 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +0,0 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,24 @@ | ||
import { useState } from 'react' | ||
import reactLogo from './assets/react.svg' | ||
import viteLogo from '/vite.svg' | ||
import './App.css' | ||
import { useState } from "react"; | ||
import PlayerInfo from "./Components/PlayerInfo"; | ||
import Board from "./Components/Board"; | ||
import Dice from "./Components/Dice"; | ||
|
||
function App() { | ||
const [count, setCount] = useState(0) | ||
|
||
return ( | ||
<> | ||
<div> | ||
<a href="https://vitejs.dev" target="_blank"> | ||
<img src={viteLogo} className="logo" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank"> | ||
<img src={reactLogo} className="logo react" alt="React logo" /> | ||
</a> | ||
</div> | ||
<h1>Vite + React</h1> | ||
<div className="card"> | ||
<button onClick={() => setCount((count) => count + 1)}> | ||
count is {count} | ||
</button> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to test HMR | ||
</p> | ||
<div className="grid grid-cols-3 p-2"> | ||
<div className="border border-red-500 p-2"> | ||
<PlayerInfo /> | ||
</div> | ||
<div className="border border-red-500 p-2"> | ||
<Board /> | ||
</div> | ||
<div className="border border-red-500 p-2"> | ||
<Dice/> | ||
</div> | ||
</div> | ||
<p className="read-the-docs"> | ||
Click on the Vite and React logos to learn more | ||
</p> | ||
</> | ||
) | ||
); | ||
} | ||
|
||
export default App | ||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
const Board = () => { | ||
return <div>Board</div>; | ||
}; | ||
|
||
export default Board; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { diceValue } from "../states/DiceStates"; | ||
import { diceRoll, DiceValToIconMap } from "../Utils"; | ||
import { | ||
currentPlayer, | ||
gameLogs, | ||
gameState, | ||
playerPositions, | ||
} from "../states/BoardStates"; | ||
|
||
const Dice = () => { | ||
const [diceVal, setDiceVal] = useRecoilState(diceValue); | ||
const [gameLog, setGameLog] = useRecoilState(gameLogs); | ||
const [currPlayer, setCurrPlayer] = useRecoilState(currentPlayer); | ||
const [playerPos, setPlayerPos] = useRecoilState(playerPositions); | ||
const [gState, setGState] = useRecoilState(gameState); | ||
|
||
const rollDice = () => { | ||
const newVal = diceRoll(); | ||
const newPlayer = currPlayer === 1 ? 2 : 1; | ||
const isPlayerFree = newVal === 6; | ||
setDiceVal(newVal); | ||
setGameLog([ | ||
...gameLog, | ||
`Player ${currPlayer} Rolled Dice to ${newVal}`, | ||
...(isPlayerFree ? [`Player ${currPlayer} is Free to Move`] : []), | ||
`Player ${newPlayer}'s Turn`, | ||
]); | ||
setCurrPlayer(newPlayer); | ||
setPlayerPos({ | ||
player1: | ||
currPlayer === 1 && isPlayerFree && !gState["player1"].move | ||
? newVal | ||
: gState["player1"].move && currPlayer === 1 | ||
? playerPos.player1 + newVal | ||
: playerPos.player1, | ||
player2: | ||
currPlayer === 2 && isPlayerFree && !gState["player2"].move | ||
? newVal | ||
: gState["player2"].move && currPlayer === 2 | ||
? playerPos.player2 + newVal | ||
: playerPos.player2, | ||
}); | ||
if (isPlayerFree) { | ||
setGState({ ...gState, [`player${currPlayer}`]: { move: true } }); | ||
} else { | ||
setGState({ ...gState, global: "started" }); | ||
} | ||
console.log("Game states", gState); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="flex justify-center content-center items-center"> | ||
<div className="cursor-pointer" onClick={rollDice}> | ||
{DiceValToIconMap[diceVal]} | ||
</div> | ||
</div> | ||
<div className="grid"> | ||
<i className="justify-self-center">Click to Roll Dice</i> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import { useRecoilState, useRecoilValue } from "recoil"; | ||
import { gameLogs, playerPositions } from "../states/BoardStates"; | ||
|
||
const PlayerInfo = () => { | ||
const [playerPos, setPlayerPos] = useRecoilState(playerPositions); | ||
const gLogs = useRecoilValue(gameLogs); | ||
return ( | ||
<div> | ||
<h3>Game Logs</h3> | ||
<div className="border border-gray-500 overflow-auto h-20"> | ||
{gLogs?.map((log) => ( | ||
<p className="p-1">{log}</p> | ||
))} | ||
</div> | ||
<h3>Player Positions</h3> | ||
<p>Player 1 :- {playerPos.player1}</p> | ||
<p>Player 2 :- {playerPos.player2}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PlayerInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IoDice } from "react-icons/io5"; | ||
import { FaDiceOne } from "react-icons/fa6"; | ||
import { FaDiceTwo } from "react-icons/fa6"; | ||
import { FaDiceThree } from "react-icons/fa6"; | ||
import { FaDiceFour } from "react-icons/fa"; | ||
import { FaDiceFive } from "react-icons/fa"; | ||
import { FaDiceSix } from "react-icons/fa6"; | ||
|
||
export const DiceValToIconMap = { | ||
0: <IoDice size={150} />, | ||
1: <FaDiceOne size={150} />, | ||
2: <FaDiceTwo size={150} />, | ||
3: <FaDiceThree size={150} />, | ||
4: <FaDiceFour size={150} />, | ||
5: <FaDiceFive size={150} />, | ||
6: <FaDiceSix size={150} />, | ||
}; | ||
|
||
export const diceRoll = () => { | ||
return Math.trunc(Math.random() * 6 + 1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,3 @@ | ||
:root { | ||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; | ||
line-height: 1.5; | ||
font-weight: 400; | ||
|
||
color-scheme: light dark; | ||
color: rgba(255, 255, 255, 0.87); | ||
background-color: #242424; | ||
|
||
font-synthesis: none; | ||
text-rendering: optimizeLegibility; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
a { | ||
font-weight: 500; | ||
color: #646cff; | ||
text-decoration: inherit; | ||
} | ||
a:hover { | ||
color: #535bf2; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
display: flex; | ||
place-items: center; | ||
min-width: 320px; | ||
min-height: 100vh; | ||
} | ||
|
||
h1 { | ||
font-size: 3.2em; | ||
line-height: 1.1; | ||
} | ||
|
||
button { | ||
border-radius: 8px; | ||
border: 1px solid transparent; | ||
padding: 0.6em 1.2em; | ||
font-size: 1em; | ||
font-weight: 500; | ||
font-family: inherit; | ||
background-color: #1a1a1a; | ||
cursor: pointer; | ||
transition: border-color 0.25s; | ||
} | ||
button:hover { | ||
border-color: #646cff; | ||
} | ||
button:focus, | ||
button:focus-visible { | ||
outline: 4px auto -webkit-focus-ring-color; | ||
} | ||
|
||
@media (prefers-color-scheme: light) { | ||
:root { | ||
color: #213547; | ||
background-color: #ffffff; | ||
} | ||
a:hover { | ||
color: #747bff; | ||
} | ||
button { | ||
background-color: #f9f9f9; | ||
} | ||
} | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
import './index.css' | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App.tsx"; | ||
import "./index.css"; | ||
import { RecoilRoot } from "recoil"; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) | ||
<RecoilRoot> | ||
<App /> | ||
</RecoilRoot> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { atom } from "recoil"; | ||
|
||
export const playerPositions = atom({ | ||
key: "playerPositions", | ||
default: { | ||
player1: 0, | ||
player2: 0, | ||
}, | ||
}); | ||
|
||
export const gameLogs = atom({ | ||
key: "gameLogs", | ||
default: ["Player 1 Click Dice to Start Game"], | ||
}); | ||
|
||
export const currentPlayer = atom({ | ||
key: "currentPlayer", | ||
default: 1, | ||
}); | ||
|
||
export const gameState = atom({ | ||
key: "gameState", | ||
default: { | ||
global: "notStarted", // notStarted || started || over | ||
player1: { | ||
move: false, | ||
}, | ||
player2: { | ||
move: false, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { atom } from "recoil"; | ||
|
||
export const diceValue = atom({ | ||
key: "diceValue", | ||
default: 0, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
}; |