diff --git a/assets/javascript/game.js b/assets/javascript/game.js index e57e1a1..789c9a0 100644 --- a/assets/javascript/game.js +++ b/assets/javascript/game.js @@ -25,14 +25,23 @@ window.Game = React.createClass({ } $.get('/game/' + this.props.gameID, (data) => { - if (this.state.game && data.created_at != this.state.game.created_at) { - this.setState({codemaster: false}); - } + if (this.state.game) { + if (data.round != this.state.game.round) { + this.changedTurn(); + } + if (data.created_at != this.state.game.created_at) { + this.setState({codemaster: false}); + } + } this.setState({game: data}); setTimeout(this.refresh, 3000); }); }, + changedTurn: function() { + this.setState({hasClue: false}); + }, + toggleRole: function(e, role) { e.preventDefault(); this.setState({codemaster: role=='codemaster'}); @@ -77,7 +86,7 @@ window.Game = React.createClass({ endTurn: function() { $.post('/end-turn', JSON.stringify({game_id: this.state.game.id}), - (g) => { this.setState({game: g}); }); + (g) => { this.setState({game: g}); this.changedTurn(); }); }, nextGame: function(e) { @@ -86,6 +95,19 @@ window.Game = React.createClass({ (g) => { this.setState({game: g, codemaster: false}) }); }, + giveClue: function(e) { + let clueWord = $('#clue-word')[0].value; + let clueCount = parseInt($('#clue-count')[0].value); + // How does this not have an error callback :( + $.post('/clue', JSON.stringify({ + game_id: this.state.game.id, + word: clueWord, + count: clueCount + }), (g) => { + this.setState({game: g, hasClue: true}); + }); + }, + render: function() { if (!this.state.game) { return (
Loading…
); @@ -110,6 +132,23 @@ window.Game = React.createClass({ otherTeam = 'red'; } + let clueDOM; + if (this.state.codemaster) { + clueDOM = ( +