From 056cbd0ef7160bf393b14d60d23679bbe6c4845b Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 28 Aug 2022 16:30:44 +0300 Subject: [PATCH] done --- src/components/Field.js | 6 ++++-- src/screens/Game.js | 20 ++++++++++++++++---- src/screens/Home.js | 2 -- src/screens/NewGame.js | 11 ----------- 4 files changed, 20 insertions(+), 19 deletions(-) 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

diff --git a/src/screens/Home.js b/src/screens/Home.js index e554d68..8782f70 100644 --- a/src/screens/Home.js +++ b/src/screens/Home.js @@ -20,8 +20,6 @@ class Home extends Component {

Sprint Battleship

-
- ); } diff --git a/src/screens/NewGame.js b/src/screens/NewGame.js index fbef7d1..881f5c5 100644 --- a/src/screens/NewGame.js +++ b/src/screens/NewGame.js @@ -94,17 +94,6 @@ class NewGame extends Component { return (

Расставь корабли

- {/*
-
-

Player1

- -
-
-
-

Player2

- -
-
*/}

Player1