-
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.
Merge pull request #66 from ClaudioMartinH/64-create-main-page
64 create main page
- Loading branch information
Showing
6 changed files
with
142 additions
and
22 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,26 @@ | ||
import React from 'react'; | ||
import { GiInvertedDice1, GiInvertedDice2, GiInvertedDice3, GiInvertedDice4, GiInvertedDice5, GiInvertedDice6 } from 'react-icons/gi'; | ||
|
||
interface DiceProps { | ||
face: 1 | 2 | 3 | 4 | 5 | 6; | ||
rolling: boolean | ||
} | ||
|
||
const Dice: React.FC<DiceProps> = ({ face, rolling }) => { | ||
const diceComponents: Record<number, JSX.Element> = { | ||
1: <GiInvertedDice1 className={`text-white text-9xl ${rolling && "animate-wobble"}`} />, | ||
2: <GiInvertedDice2 className={`text-white text-9xl ${rolling && "animate-wobble"}`} />, | ||
3: <GiInvertedDice3 className={`text-white text-9xl ${rolling && "animate-wobble"}`} />, | ||
4: <GiInvertedDice4 className={`text-white text-9xl ${rolling && "animate-wobble"}`} />, | ||
5: <GiInvertedDice5 className={`text-white text-9xl ${rolling && "animate-wobble"}`} />, | ||
6: <GiInvertedDice6 className={`text-white text-9xl ${rolling && "animate-wobble"}`} /> | ||
}; | ||
|
||
return ( | ||
<div> | ||
{diceComponents[face]} | ||
</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,54 @@ | ||
import { useState } from "react"; | ||
import Dice from "./Dice"; | ||
|
||
const RollDice = () => { | ||
const [state, setState] = useState({ | ||
dice1: 1 as 1 | 2 | 3 | 4 | 5 | 6, | ||
dice2: 1 as 1 | 2 | 3 | 4 | 5 | 6, | ||
rolling: false, | ||
result: "", | ||
totalScore: 0, | ||
rollCount: 0 | ||
}); | ||
|
||
const { dice1, dice2, rolling, result, totalScore, rollCount } = state | ||
|
||
const roll = () => { | ||
const newDice1 = Math.floor(Math.random() * 6) + 1 as 1 | 2 | 3 | 4 | 5 | 6; | ||
const newDice2 = Math.floor(Math.random() * 6) + 1 as 1 | 2 | 3 | 4 | 5 | 6; | ||
const score = newDice1 + newDice2; | ||
const result = score > 7 ? "You Win!" : "You Loose!" | ||
const newScore = score > 7 ? totalScore + 1 : totalScore | ||
const newCount = rollCount + 1 | ||
setState({ | ||
dice1: newDice1, | ||
dice2: newDice2, | ||
rolling: true, | ||
result: result, | ||
totalScore: newScore, | ||
rollCount: newCount | ||
}); | ||
|
||
setTimeout(() => { | ||
setState((prevState) => ({...prevState, rolling: false})) | ||
}, 1000); | ||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
<div className="flex justify-center space-x-6 my-4"> | ||
<Dice face={dice1} rolling={rolling} /> | ||
<Dice face={dice2} rolling={rolling} /> | ||
</div> | ||
<button onClick={roll} disabled={rolling} className="py-3 px-6 m-2 rounded-md bg-gradient-to-r from-cyan-500 to-blue-500 text-white text-lg font-semibold hover:opacity-85"> | ||
{rolling ? "Rolling..." : "Roll Dice"} | ||
</button> | ||
<p className="text-white text-2xl">{result}</p> | ||
<p className="text-white text-2xl">Total Score: {totalScore} / {rollCount}</p> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default RollDice; |
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,16 @@ | ||
import dice from '../assets/dice.jpg' | ||
import RollDice from '../components/RollDice'; | ||
|
||
|
||
const MainPage: React.FC = () => { | ||
|
||
return ( | ||
<section className='flex justify-center items-center min-h-full p-20 bg-slate-800' style={{ backgroundImage: `url(${dice})`, backgroundSize: 'cover', backgroundPosition: 'center' }}> | ||
<div className='p-20 min-w-full rounded-xl border border-slate-500 backdrop-blur-lg shadow-md shadow-slate-600'> | ||
<RollDice /> | ||
</div> | ||
</section> | ||
); | ||
}; | ||
|
||
export default MainPage; |
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,11 +1,28 @@ | ||
import { transform } from 'typescript'; | ||
|
||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: [ | ||
"./index.html", | ||
"./src/**/*.{js,ts,jsx,tsx}", | ||
], | ||
theme: { | ||
extend: {}, | ||
extend: { | ||
animation: { | ||
wobble: 'wobble 1s ease-in-out' | ||
}, | ||
keyframes: { | ||
wobble: { | ||
'0%': { transform: 'translate3d(0,0,0)' }, | ||
'15%': { transform: 'translate3d(-25%,0,0) rotate3d(0,0,1, -5deg)' }, | ||
'30%': { transform: 'translate3d(20%,0,0) rotate3d(0,0,1, 3deg)' }, | ||
'45%': { transform: 'translate3d(-15%,0,0) rotate3d(0,0,1, -3deg)' }, | ||
'60%': { transform: 'translate3d(10%,0,0) rotate3d(0,0,1, 2deg)' }, | ||
'75%': { transform: 'translate3d(-5%,0,0) rotate3d(0,0,1, -1deg)' }, | ||
'100%': { transform: 'translate3d(0,0,0)' }, | ||
} | ||
} | ||
}, | ||
}, | ||
plugins: [], | ||
} |