diff --git a/src/components/Field.js b/src/components/Field.js index 3ecd856..f1eb863 100644 --- a/src/components/Field.js +++ b/src/components/Field.js @@ -43,7 +43,8 @@ class Cell extends Component { shoot() { this.props.parent.setState({ - changeable: false + changeable: false, + text: "Подожди" }) request("shoot", { game_id: localStorage.getItem("gameId"), @@ -65,7 +66,6 @@ class Cell extends Component { click() { if (!this.state.changeable) return; - if (this.state.shotState !== " ") return; if (this.props.parent.props.ready) this.shoot(); else @@ -80,6 +80,8 @@ class Cell extends Component { color = "darkcyan"; } else if (this.state.shotState === ".") { color = "gray"; + } else if (this.symb === "o") { + color = "green"; } return ( diff --git a/src/screens/Game.js b/src/screens/Game.js index 8d9aa5f..857c867 100644 --- a/src/screens/Game.js +++ b/src/screens/Game.js @@ -9,7 +9,8 @@ class Game extends Component { this.state = { myField: null, opponentField: null, - myTurn: false + myTurn: false, + text: "" } } @@ -19,8 +20,15 @@ class Game extends Component { this.setState({ myField: response.my_field, opponentField: response.opponent_field, - myTurn: response.my_turn + myTurn: response.my_turn, + text: response.my_turn ? "Твой ход" : "Ход соперника" }) + if (response.game_finished) { + this.setState({ + text: "Игра окончена" + }) + this.timer = null; + } } request("get_fields", { game_id: localStorage.getItem("gameId"), @@ -29,7 +37,7 @@ class Game extends Component { } componentDidMount() { - this.timer = setInterval(() => this.doUpdate(), 2000); + this.timer = setInterval(() => this.doUpdate(), 500); } render() { @@ -41,7 +49,11 @@ class Game extends Component {
Player1
+ {this.state.text} +
+Player2
Sprint Battleship
Расставь корабли
Player1
-Player2
-Player1