Private
Public Access
1
0

bugfix points saving and exploded bombs to db && you can resign #6

This commit is contained in:
2016-11-20 17:44:29 +01:00
parent 180c827380
commit 5a3ce73e40
8 changed files with 242 additions and 87 deletions

View File

@@ -46,22 +46,24 @@ class MineSeeker extends React.Component {
redPoints += activePlayer === 'red' ? mineCache : 0;
bluePoints += activePlayer === 'blue' ? mineCache : 0;
return {red: bluePoints, blue: redPoints};
return {red: redPoints, blue: bluePoints};
}
/** THE END */
makeGameEndIfItEnds(bluePoints, redPoints) {
makeGameEndIfItEnds(bluePoints, redPoints, resign = false) {
var redWins = redPoints > 2,
blueWins = bluePoints > 2;
if (redWins || blueWins) {
if (redWins || blueWins || resign) {
this.refs.gridControl.state.sound.won.play();
this.refs.gridControl.setState({
overlay: true,
overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!",
overlaySubTitle: "Play again!"
});
if (false === resign) {
this.refs.gridControl.setState({
overlay: true,
overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!",
overlaySubTitle: "Play again!"
});
}
this.refs.gridControl.showLeftMines();
@@ -71,6 +73,51 @@ class MineSeeker extends React.Component {
}
}
resignProcess(color) {
this.refs.gridControl.setState({
overlay: true,
overlayTitle: color === this.refs.gridControl.state.webPlayer
? "You have been give up"
: "Your opponent has been resigned",
overlaySubTitle: color === this.refs.gridControl.state.webPlayer
? "You LOSE!"
: "You WIN!"
});
this.makeGameEndIfItEnds(0, 0, true);
}
clickResign() {
this.state.session
.publish(this.state.channel, {
'resign': this.refs.gridControl.refs.userControl.state.activePlayer ? 'blue' : 'red'
});
this.resignProcess(this.refs.gridControl.state.webPlayer);
}
clickResignCancel() {
this.refs.gridControl.setState({
overlay: false
});
}
/** RESIGN */
resign() {
let users = this.refs.gridControl.refs.userControl,
activePlayer = users.state.activePlayer ? 'blue' : 'red';
if (this.refs.gridControl.state.webPlayer === activePlayer) {
this.refs.gridControl.setState({
overlay: true,
overlayTitle: "Are u sure u want to resign?!",
overlaySubTitle: <div className="resign">
<a onClick={this.clickResign.bind(this)}>Yes</a>
<a onClick={this.clickResignCancel.bind(this)}>No!</a>
</div>
});
}
}
/** after rendering */
componentDidMount() {
/** Create Websocket w/ Bahnhof.js */
@@ -143,19 +190,25 @@ class MineSeeker extends React.Component {
isNotUnsubscribe = typeof payload.msg === 'undefined';
if (isTopicEvent) {
console.warn(payload.user + " has been stepped to coords: " + payload.data.coords[0] + ', ' + payload.data.coords[1]);
/** Auto-Step if this player is not the current user */
if (this.refs.gridControl.state.webPlayer !== payload.data.player) {
console.warn('Opponent stepped: Auto-Step process');
if (null === payload.data.resign) {
console.warn(payload.user + " has been stepped to coords: " + payload.data.coords[0] + ', ' + payload.data.coords[1]);
console.warn('Opponent stepped: Auto-Step process');
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb});
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb});
/** STEP */
let points = this.makePointsCalcAndStep(payload.data.coords);
/** STEP */
let points = this.makePointsCalcAndStep(payload.data.coords);
/** THE END */
this.makeGameEndIfItEnds(points.blue, points.red);
/** THE END */
this.makeGameEndIfItEnds(points.blue, points.red);
} else {
/** RESIGN */
/** THE END */
this.resignProcess(payload.data.resign);
}
}
} else {
@@ -235,7 +288,10 @@ class MineSeeker extends React.Component {
'player': activePlayer,
'bomb': this.refs.gridControl.refs.userControl.state.bombSelected,
'redPoints': points.red,
'bluePoints': points.blue
'bluePoints': points.blue,
'resign': null,
'redExplodedBomb': activePlayer === 'red' && this.refs.gridControl.refs.userControl.state.bombSelected,
'blueExplodedBomb': activePlayer === 'blue' && this.refs.gridControl.refs.userControl.state.bombSelected
});
}
}
@@ -245,6 +301,7 @@ class MineSeeker extends React.Component {
return (
<GridControl ref="gridControl"
env={this.props.env === 'dev'}
resign={this.resign.bind(this)}
onClick={this.onClick.bind(this)}/>
);
}