diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml
index 46f7570..0cb711f 100644
--- a/.deploy/deploy-dev.yaml
+++ b/.deploy/deploy-dev.yaml
@@ -7,6 +7,8 @@ services:
image: mathwave/sprint-repo:battleship-front
networks:
- battleship-net
+ environment:
+ HOST_URL: "http://battleship.develop.sprinthub.ru/"
deploy:
mode: replicated
restart_policy:
diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml
index 46f7570..0cb711f 100644
--- a/.deploy/deploy-prod.yaml
+++ b/.deploy/deploy-prod.yaml
@@ -7,6 +7,8 @@ services:
image: mathwave/sprint-repo:battleship-front
networks:
- battleship-net
+ environment:
+ HOST_URL: "http://battleship.develop.sprinthub.ru/"
deploy:
mode: replicated
restart_policy:
diff --git a/src/components/Field.js b/src/components/Field.js
index 236a8a9..7f3db22 100644
--- a/src/components/Field.js
+++ b/src/components/Field.js
@@ -12,15 +12,30 @@ class Cell extends Component {
}
}
- click() {
- if (!this.props.changeable) return;
+ changeColor() {
if (this.state.color === "white")
this.setState({color: "green"});
else
this.setState({color: "white"});
+ this.props.parent.props.parent.update();
+ }
+
+ shoot() {
+
+ }
+
+ click() {
+ if (!this.props.changeable) return;
+ if (this.props.parent.props.ready)
+ this.shoot();
+ else
+ this.changeColor();
}
render() {
+ this.props.parent.cells.push(this);
+ this.props.parent.cells.sort((a, b) => a.key < b.key);
+ console.log(this.props.parent.cells.length);
return (
)
@@ -29,16 +44,32 @@ class Cell extends Component {
class Field extends Component {
+ constructor(props) {
+ super(props);
+
+ props.parent.field = this;
+
+ this.getLine = () => {
+ let line = "";
+ for (let i = 0; i < 100; i++) {
+ line += this.cells.at(i).state.color === "white" ? " " : "o";
+ }
+ return line;
+ }
+
+ }
+
render() {
- let cells = []
+ this.cells = [];
+ let cells = [];
for (let i = 0; i < 10; i++) {
let line = []
for (let j = 0; j < 10; j++) {
- line.push(
| | );
+ const cell = | ;
+ line.push({cell} | );
}
cells.push({line}
);
}
-
return (
diff --git a/src/components/Ready.js b/src/components/Ready.js
index 87d2ece..f41b69b 100644
--- a/src/components/Ready.js
+++ b/src/components/Ready.js
@@ -4,14 +4,29 @@ export default class Ready extends Component {
constructor(props) {
super(props);
+ this.update();
this.state = {
text: "Расставь корабли чтобы активировать",
disabled: true
}
}
+ update() {
+ if (!this.props.ok)
+ this.setState({
+ text: "Расставь корабли чтобы активировать",
+ disabled: true
+ })
+ else
+ this.setState({
+ text: "Я готов",
+ disabled: false
+ })
+ this.props.parent.ready = this;
+ }
+
render() {
- return
+ return
}
}
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index d563c0f..26a2c71 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,9 +6,7 @@ import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
-
-
);
// If you want to start measuring performance in your app, pass a function
diff --git a/src/screens/NewGame.js b/src/screens/NewGame.js
index 233edb9..4f1001d 100644
--- a/src/screens/NewGame.js
+++ b/src/screens/NewGame.js
@@ -3,7 +3,7 @@ import '../styles/styles.css';
import '../styles/bootstrap.css';
import Field from '../components/Field.js';
import Ready from '../components/Ready.js';
-import {host} from '../scripts/requests.js';
+import request, {host} from '../scripts/requests.js';
class NewGame extends Component {
@@ -12,12 +12,28 @@ class NewGame extends Component {
return queryParams.get('playerToken');
}
+ constructor(props) {
+ super(props);
+ this.state = {
+ ok: false
+ }
+ }
+
+ update() {
+ const line = this.field.getLine();
+ request("check_field_correct", {field: line}, (response) => {
+ this.setState({ok: response.correct});
+ this.ready.setState({ok: this.state.ok});
+ this.ready.update();
+ });
+ }
+
render() {
return (
Расставь корабли
-
+ {/*
Player1
@@ -27,12 +43,18 @@ class NewGame extends Component {
Player2
+
*/}
+
Ссылка для подключения
-
+
);
}
diff --git a/src/scripts/requests.js b/src/scripts/requests.js
index 5c46c93..ed3f0cc 100644
--- a/src/scripts/requests.js
+++ b/src/scripts/requests.js
@@ -1,8 +1,15 @@
-export const host = "http://battleship.develop.sprinthub.ru/";
+var h = null;
+if (process.env.HOST_URL !== undefined) {
+ h = process.env.HOST_URL;
+} else {
+ h = "http://127.0.0.1:8000/";
+}
+
+export const host = h;
function request(method, body, callback) {
- const options = {
+ const options = {
method: 'POST',
body: JSON.stringify(body),
headers: {