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-18 12:57:20 +02:00
|
|
|
import React, { Fragment, useState } 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-18 12:57:20 +02:00
|
|
|
import BonusStatsDialog from '../BonusStatsDialog';
|
2026-04-21 11:30:07 +02:00
|
|
|
import { func } from 'prop-types';
|
2026-04-10 17:57:26 +02:00
|
|
|
|
2026-04-10 19:09:05 +02:00
|
|
|
const UserControl = ({ resign }) => {
|
2026-04-19 21:31:08 +02:00
|
|
|
const { webPlayer, activePlayer, foundMines, red, blue, onBombToggle } = useGame();
|
2026-04-18 12:57:20 +02:00
|
|
|
const [bonusDialogOpen, setBonusDialogOpen] = useState(false);
|
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' : '');
|
2026-04-19 21:31:08 +02:00
|
|
|
const remainingMines = 51 - red.mines - blue.mines;
|
2026-04-10 17:57:26 +02:00
|
|
|
|
|
|
|
|
const handleBombClick = (color, player) => {
|
|
|
|
|
const p = 'red' === color ? red : blue;
|
|
|
|
|
if (p.haveBomb && p.enabledBomb && activePlayer === player) {
|
|
|
|
|
onBombToggle();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-18 12:57:20 +02:00
|
|
|
const handleBonusClick = () => {
|
|
|
|
|
setBonusDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-10 17:57:26 +02:00
|
|
|
return (
|
2026-04-18 12:57:20 +02:00
|
|
|
<Fragment>
|
|
|
|
|
<div className="users">
|
|
|
|
|
<User
|
|
|
|
|
color="blue" webPlayer={webPlayer} {...blue}
|
|
|
|
|
onClickBombSelector={() => handleBombClick('blue', 1)}
|
|
|
|
|
onBonusClick={handleBonusClick}
|
|
|
|
|
/>
|
|
|
|
|
<div className="active-mines-container">
|
|
|
|
|
<i className="fa fa-star" />
|
|
|
|
|
<div className={minesClass}>
|
2026-04-19 21:31:08 +02:00
|
|
|
<div className="active-mines-nbr">{remainingMines}</div>
|
2026-04-18 12:57:20 +02:00
|
|
|
<div className="active-mines-shine" />
|
|
|
|
|
</div>
|
|
|
|
|
<i className="fa fa-star" />
|
2026-04-10 17:57:26 +02:00
|
|
|
</div>
|
2026-04-18 12:57:20 +02:00
|
|
|
<div className="clear" />
|
|
|
|
|
<User
|
|
|
|
|
color="red" webPlayer={webPlayer} {...red}
|
|
|
|
|
onClickBombSelector={() => handleBombClick('red', 0)}
|
|
|
|
|
onBonusClick={handleBonusClick}
|
|
|
|
|
/>
|
|
|
|
|
<button className={resignClass} onClick={resign}>
|
|
|
|
|
<div className="resign-shine" />
|
|
|
|
|
Resign
|
|
|
|
|
</button>
|
2026-04-10 17:57:26 +02:00
|
|
|
</div>
|
2026-04-18 12:57:20 +02:00
|
|
|
<BonusStatsDialog
|
|
|
|
|
open={bonusDialogOpen}
|
|
|
|
|
onClose={() => setBonusDialogOpen(false)}
|
|
|
|
|
red={red}
|
|
|
|
|
blue={blue}
|
2026-04-10 17:57:26 +02:00
|
|
|
/>
|
2026-04-18 12:57:20 +02:00
|
|
|
</Fragment>
|
2026-04-10 17:57:26 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserControl;
|
2026-04-21 11:30:07 +02:00
|
|
|
|
|
|
|
|
UserControl.propTypes = {
|
|
|
|
|
resign: func.isRequired,
|
|
|
|
|
};
|