2026-04-10 21:53:50 +02:00
|
|
|
/**
|
|
|
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-10 17:57:26 +02:00
|
|
|
import React from 'react';
|
2026-04-10 21:53:50 +02:00
|
|
|
import { useGame } from '@mine-contexts';
|
2026-04-10 17:57:26 +02:00
|
|
|
import User from './User';
|
|
|
|
|
|
2026-04-10 19:09:05 +02:00
|
|
|
const UserControl = ({ resign }) => {
|
|
|
|
|
const { webPlayer, activePlayer, mines, foundMines, red, blue, onBombToggle } = useGame();
|
2026-04-10 17:57:26 +02:00
|
|
|
const activeColor = activePlayer ? 'blue' : 'red';
|
|
|
|
|
const resignClass = 'resign' + (activeColor !== webPlayer ? ' disabled' : '');
|
|
|
|
|
const minesClass = 'active-mines' + (foundMines ? ' found-mine' : '');
|
|
|
|
|
|
|
|
|
|
const handleBombClick = (color, player) => {
|
|
|
|
|
const p = 'red' === color ? red : blue;
|
|
|
|
|
if (p.haveBomb && p.enabledBomb && activePlayer === player) {
|
|
|
|
|
onBombToggle();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="users">
|
|
|
|
|
<User
|
|
|
|
|
color="blue" webPlayer={webPlayer} {...blue}
|
|
|
|
|
onClickBombSelector={() => handleBombClick('blue', 1)}
|
|
|
|
|
/>
|
|
|
|
|
<div className="active-mines-container">
|
|
|
|
|
<i className="fa fa-star" />
|
|
|
|
|
<div className={minesClass}>
|
|
|
|
|
<div className="active-mines-nbr">{mines}</div>
|
|
|
|
|
<div className="active-mines-shine" />
|
|
|
|
|
</div>
|
|
|
|
|
<i className="fa fa-star" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="clear" />
|
|
|
|
|
<User
|
|
|
|
|
color="red" webPlayer={webPlayer} {...red}
|
|
|
|
|
onClickBombSelector={() => handleBombClick('red', 0)}
|
|
|
|
|
/>
|
|
|
|
|
<button className={resignClass} onClick={resign}>
|
|
|
|
|
<div className="resign-shine" />
|
|
|
|
|
Resign
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserControl;
|