js and config refactor
This commit is contained in:
@@ -5,26 +5,24 @@ class UserControl extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
/**
|
||||
* activePlayer - red: 0, blue: 1
|
||||
* @type {{activePlayer: number, mines: number}}
|
||||
*/
|
||||
this.state = {
|
||||
activePlayer: 0,
|
||||
activePlayer: 0, // activePlayer - red: 0, blue: 1
|
||||
mines: 51,
|
||||
bombSelected: false,
|
||||
foundMines: false
|
||||
};
|
||||
}
|
||||
|
||||
youCanSelectBomb(activePlayer, clickedPlayer) {
|
||||
return this.refs[activePlayer].state.haveBomb &&
|
||||
this.refs[activePlayer].state.enabledBomb &&
|
||||
this.state.activePlayer === clickedPlayer;
|
||||
}
|
||||
|
||||
onClickBombSelector(clickedPlayer) {
|
||||
var activePlayer = this.state.activePlayer ? 'blue' : 'red';
|
||||
|
||||
if (
|
||||
this.refs[activePlayer].state.haveBomb &&
|
||||
this.refs[activePlayer].state.enabledBomb &&
|
||||
this.state.activePlayer === clickedPlayer
|
||||
) {
|
||||
if (this.youCanSelectBomb(activePlayer, clickedPlayer)) {
|
||||
this.state.bombSelected = !this.state.bombSelected;
|
||||
|
||||
if (!this.state.bombSelected) {
|
||||
|
||||
@@ -24,15 +24,17 @@ class User extends React.Component {
|
||||
}
|
||||
|
||||
getBomb() {
|
||||
let src = this.state.srcRoot;
|
||||
|
||||
if (this.state.haveBomb) {
|
||||
if (this.state.enabledBomb && this.state.active) {
|
||||
return this.state.srcRoot + 'bg-bomb-outbg.png';
|
||||
} else {
|
||||
return this.state.srcRoot + 'bg-bomb-disabled-outbg.png';
|
||||
}
|
||||
src += this.state.enabledBomb && this.state.active
|
||||
? 'bg-bomb-outbg.png'
|
||||
: 'bg-bomb-disabled-outbg.png';
|
||||
} else {
|
||||
return this.state.srcRoot + 'bg-bomb-exploded-outbg.png';
|
||||
src += 'bg-bomb-exploded-outbg.png';
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
getFigure(color) {
|
||||
@@ -40,10 +42,8 @@ class User extends React.Component {
|
||||
}
|
||||
|
||||
getCursor(state, color) {
|
||||
var cursorImg = this.state.srcRoot + 'bg-cursor-' + color + '-outbg.png';
|
||||
|
||||
return state
|
||||
? <img src={cursorImg} alt="cursor" className="user-cursor"/>
|
||||
? <img src={this.state.srcRoot + 'bg-cursor-' + color + '-outbg.png'} alt="cursor" className="user-cursor"/>
|
||||
: '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user