Private
Public Access
1
0

some refactor #13

This commit is contained in:
2016-11-18 20:42:29 +01:00
parent 541e2e605c
commit 25cc3910f5
3 changed files with 15 additions and 30 deletions

View File

@@ -689,6 +689,10 @@ main {
display: block;
}
/*#mine-wrapper .grid .field-wrapper.targeted > img.field-target {*/
/*display: block;*/
/*}*/
/** width = 4 x .field */
#mine-wrapper .grid .field-wrapper > img.field-bomb-target {
position: absolute;

View File

@@ -71,13 +71,12 @@ class MineSeeker extends React.Component {
(gridServer) => {
console.info("Grid has been created! Return w/ gameAssoc.");
this.state.session = session;
this.setState({session: session});
/** save session to GridControl */
/** render grid fields - #12 */
this.refs.gridControl.setState({
grid: this.state.gameInherited ? JSON.parse(Base64.decode(gridServer)) : gridClient,
session: this.state.session,
channel: this.state.channel,
overlay: true,
overlayTitle: "We are waiting for your opponent...",
@@ -88,13 +87,7 @@ class MineSeeker extends React.Component {
});
/** setup the web player */
if (this.refs.gridControl.state.webPlayer === null) {
if (this.state.gameInherited) {
this.refs.gridControl.state.webPlayer = 'blue';
} else {
this.refs.gridControl.state.webPlayer = 'red';
}
}
this.refs.gridControl.state.webPlayer === null && this.refs.gridControl.setState({webPlayer: this.state.gameInherited ? 'blue' : 'red'});
/** Connect - Subscribe */
this.state.session.subscribe(
@@ -111,7 +104,7 @@ class MineSeeker extends React.Component {
if (this.refs.gridControl.state.webPlayer !== payload.data.player) {
console.warn('Opponent stepped: Auto-Step process');
this.refs.gridControl.refs.userControl.state.bombSelected = payload.data.bomb;
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb});
this.refs.gridControl.stepEvent(payload.data.coords);
/** End-game control */
@@ -128,10 +121,8 @@ class MineSeeker extends React.Component {
(typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!"
);
var activePlayer = this.refs.gridControl.refs.userControl.state.activePlayer ? 'blue' : 'red';
/** remove overlay when every user has been came */
this.refs.gridControl.setState({ overlay: payload.userCnt < 2});
this.refs.gridControl.setState({overlay: payload.userCnt < 2});
/** Set up player names w/ server data */
this.refs.gridControl.refs.userControl.refs.red.setState({

View File

@@ -52,21 +52,10 @@ class GridControl extends React.Component {
/** if the (5x5) target not fits the grid */
if (!isBombTargetCenter) {
if (col < 2) {
col = 2;
}
if (row < 2) {
row = 2;
}
if (row > this.state.grid.length - 3) {
row = this.state.grid.length - 3;
}
if (col > this.state.grid[0].length - 3) {
col = this.state.grid[0].length - 3;
}
col = col < 2 ? 2 : col;
row = row < 2 ? 2 : row;
row = row > this.state.grid.length - 3 ? this.state.grid.length - 3 : row;
col = col > this.state.grid[0].length - 3 ? this.state.grid[0].length - 3 : col;
}
return [
@@ -362,9 +351,10 @@ class GridControl extends React.Component {
/**
* On Hover when you want to drop BOMB
* Target grid field
* @param coords
*/
onHoverWithBomb(coords) {
onHoverGridField(coords) {
if (this.refs.userControl.state.bombSelected) {
var activePlayer = this.refs.userControl.state.activePlayer ? 'blue' : 'red';
@@ -393,7 +383,7 @@ class GridControl extends React.Component {
col={k}
ref={this.refString(i, k)}
key={i + k * Math.random() * 0.5}
handleHoverOn={this.onHoverWithBomb.bind(this, [i, k])}
handleHoverOn={this.onHoverGridField.bind(this, [i, k])}
onClick={this.props.onClick.bind(null, [i, k])}/>
);
}