You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

4 years ago
import _ from 'lodash';
// @ts-ignore
import witch from '../../resources/witch.svg';
import './GamePage.css';
import { Witch } from '../../model/Witch';
import apiStore from '../../store/apiStore/apiStore';
import { useState } from 'react';
4 years ago
type GameProps = {
onExitGame: () => void,
};
const GamePage: React.FC<GameProps> = (props) => {
const {onExitGame} = props;
const [state, setState] = useState(0);
4 years ago
const clickAtWitch = (guid: string) => {
apiStore.turn(guid)
.then((result) => {
setState(result ? 1 : 2);
setTimeout(() => {
setState(0);
}, 300);
});
};
4 years ago
return (
<header className="App-header">
<div className='game'>
<div>Score: {apiStore.currentGame?.score}</div>
<div className={`witch-row state${state}`}>
4 years ago
{
_.map(apiStore.currentGame?.witches, (item: Witch, index: number) => {
const left = item.position * 100;
const top = 100;
4 years ago
return (
<div key={index} className='witch' style={{left, top}}>
4 years ago
<img src={witch} alt={`witch-${index}`} onClick={() => clickAtWitch(item.guid)}/>
</div>
)
})
}
</div>
<div className="small">Version: {apiStore.version}</div>
4 years ago
</div>
<h1 onClick={() => onExitGame()}> Стоп игра! </h1>
<div>
<label htmlFor='hasServer'>У меня, кажется, есть свой сервер!</label>
<input
type='checkbox'
id='hasServer'
checked={!apiStore.mockMode}
value='1'
onChange={(e) => apiStore.tryToSetMockMode(e.target.checked)}
/></div>
4 years ago
</header>
);
}
export default GamePage;