|
|
@ -3,6 +3,7 @@ import '../../style/basket_court.css';
|
|
|
|
import React, {MouseEvent, ReactElement, useRef, useState} from "react";
|
|
|
|
import React, {MouseEvent, ReactElement, useRef, useState} from "react";
|
|
|
|
import Player from "./Player";
|
|
|
|
import Player from "./Player";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TEAM_MAX_PLAYER = 5;
|
|
|
|
|
|
|
|
|
|
|
|
export function BasketCourt() {
|
|
|
|
export function BasketCourt() {
|
|
|
|
const [players, setPlayers] = useState<ReactElement[]>([])
|
|
|
|
const [players, setPlayers] = useState<ReactElement[]>([])
|
|
|
@ -15,11 +16,18 @@ export function BasketCourt() {
|
|
|
|
backgroundImage: `url(${courtSvg})`
|
|
|
|
backgroundImage: `url(${courtSvg})`
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
onClick={(e: MouseEvent) => {
|
|
|
|
onClick={(e: MouseEvent) => {
|
|
|
|
let bounds = divRef.current.getBoundingClientRect();
|
|
|
|
if (e.target != divRef.current)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
let bounds = divRef.current!.getBoundingClientRect();
|
|
|
|
|
|
|
|
let playerCount = players.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (playerCount >= TEAM_MAX_PLAYER) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const player = (
|
|
|
|
const player = (
|
|
|
|
<Player key={players.length}
|
|
|
|
<Player key={playerCount}
|
|
|
|
id={players.length + 1}
|
|
|
|
id={playerCount + 1}
|
|
|
|
x={e.clientX - bounds.x}
|
|
|
|
x={e.clientX - bounds.x}
|
|
|
|
y={e.clientY - bounds.y}
|
|
|
|
y={e.clientY - bounds.y}
|
|
|
|
bounds={{bottom: bounds.height, top: 0, left: 0, right: bounds.width}}
|
|
|
|
bounds={{bottom: bounds.height, top: 0, left: 0, right: bounds.width}}
|
|
|
|