2019-10-27 13:35:33 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
class User extends React.Component {
|
2026-04-09 15:08:00 +02:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
this.state = {
|
|
|
|
|
name: '...',
|
|
|
|
|
desc: '',
|
|
|
|
|
active: props.active,
|
|
|
|
|
color: 'blue' === props.color ? 1 : 0,
|
|
|
|
|
mines: 0,
|
|
|
|
|
srcRoot: '/images/',
|
|
|
|
|
haveBomb: true,
|
|
|
|
|
enabledBomb: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
setColor(color) {
|
|
|
|
|
return 'user-container user-' + color;
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
getSrc(color) {
|
|
|
|
|
return this.state.srcRoot + 'bg-flag-' + color + '-outbg.png';
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
getBombBuzzClass(webPlayer) {
|
|
|
|
|
let activePlayer = 1 === this.state.color ? 'blue' : 'red';
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
return 'bomb-container'
|
|
|
|
|
+ (
|
|
|
|
|
this.state.active && (activePlayer === webPlayer) && this.state.haveBomb && this.state.enabledBomb
|
|
|
|
|
? ' buzz'
|
|
|
|
|
: ''
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
getBomb() {
|
|
|
|
|
let src = this.state.srcRoot;
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
if (this.state.haveBomb) {
|
|
|
|
|
src += this.state.enabledBomb && this.state.active
|
|
|
|
|
? 'bg-bomb-outbg.png'
|
|
|
|
|
: 'bg-bomb-disabled-outbg.png';
|
|
|
|
|
} else {
|
|
|
|
|
src += 'bg-bomb-exploded-outbg.png';
|
2019-10-27 13:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
return src;
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
getFigure(color) {
|
|
|
|
|
return this.state.srcRoot + 'bg-figure-' + color + '-outbg.png';
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
|
2026-04-09 15:08:00 +02:00
|
|
|
getCursor(state, color) {
|
|
|
|
|
return state
|
|
|
|
|
? <img src={this.state.srcRoot + 'bg-cursor-' + color + '-outbg.png'} alt="cursor" className="user-cursor" />
|
|
|
|
|
: '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div className={this.setColor(this.props.color)}>
|
|
|
|
|
<div className="user-header">
|
|
|
|
|
<div className="user-color">{this.props.color}</div>
|
|
|
|
|
{this.getCursor(this.props.active, this.props.color)}
|
|
|
|
|
<img src={this.getFigure(this.props.color)} alt="figure" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="user-name"> {this.state.name} </div>
|
|
|
|
|
<div className="user-caret"><i className="fa fa-caret-down" /></div>
|
|
|
|
|
<div className="user-desc"> {this.state.desc} </div>
|
|
|
|
|
<div className="user-control">
|
|
|
|
|
<img src={this.getSrc(this.props.color)} alt="flag" />
|
|
|
|
|
<div className="user-control-mines">
|
|
|
|
|
{this.state.mines}
|
|
|
|
|
</div>
|
|
|
|
|
<div className={this.getBombBuzzClass(this.props.webPlayer)} onClick={this.props.onClickBombSelector}>
|
|
|
|
|
<div className="bomb">
|
|
|
|
|
<img src={this.getBomb()} alt="bomb" />
|
2019-10-27 13:35:33 +01:00
|
|
|
</div>
|
2026-04-09 15:08:00 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="clear" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-10-27 13:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default User;
|