-
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.
Added dice rolling and some basic piece dragging
- Loading branch information
Dean Sofer
authored and
Dean Sofer
committed
May 13, 2024
1 parent
4f60630
commit 34361f3
Showing
26 changed files
with
65 additions
and
69 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
.dice { | ||
position: absolute; | ||
left: 20%; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
z-index: 2; | ||
} |
File renamed without changes.
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
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,12 @@ | ||
.piece { | ||
width: 20px; | ||
height: 20px; | ||
|
||
&.white { | ||
background: white; | ||
} | ||
|
||
&.black { | ||
background: black; | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 { useCallback, type DragEventHandler } from "react"; | ||
import black from './images/piece-black-2.png'; | ||
import white from './images/piece-white-2.png'; | ||
import './Piece.css' | ||
|
||
const IMAGES = { black, white } | ||
|
||
type PointProps = { | ||
pieces: number, | ||
move: (from: number, to: number) => void, | ||
position: number | ||
} | ||
|
||
export default function Point({ pieces, move, position }: PointProps) { | ||
|
||
const onDragStart: DragEventHandler = useCallback((event) => event.dataTransfer?.setData('text', position.toString()), []) | ||
const onDragOver: DragEventHandler = useCallback((event) => { event.preventDefault(); }, []) | ||
const onDropListener: DragEventHandler = useCallback((event) => { | ||
event.preventDefault(); | ||
let from = parseInt(event.dataTransfer?.getData("text")!) | ||
return move(from, position) | ||
}, [move]) | ||
|
||
const Pieces = Array.from({ length: Math.abs(pieces) }); | ||
const color = pieces > 0 ? 'white' : 'black'; | ||
|
||
return <div className="point" onDragOver={onDragOver} onDragStart={onDragStart} onDrop={onDropListener}> | ||
{Pieces.map((value, index) => <div className={`piece ${color}`} key={index}> | ||
<img src={IMAGES[color]} /> | ||
</div>)} | ||
</div> | ||
} |
This file was deleted.
Oops, something went wrong.
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