This commit is contained in:
Administrator 2022-08-24 01:52:57 +03:00
parent aedce099fe
commit a64c39d8ab
4 changed files with 27 additions and 7 deletions

View File

@ -13,10 +13,11 @@ class Cell extends Component {
} }
click() { click() {
if (!this.props.changeable) return;
if (this.state.color === "white") if (this.state.color === "white")
this.setState({color: "green"}); this.setState({color: "green"});
else else
this.setState({color: "white"}) this.setState({color: "white"});
} }
render() { render() {
@ -28,13 +29,12 @@ class Cell extends Component {
class Field extends Component { class Field extends Component {
render() { render() {
let cells = [] let cells = []
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let line = [] let line = []
for (let j = 0; j < 10; j++) { for (let j = 0; j < 10; j++) {
line.push(<td key={(i * 10 + j) * 100}><Cell key={(i * 10 + j)} h={i} v={j} /></td>); line.push(<td key={(i * 10 + j) * 100}><Cell changeable={this.props.changeable} key={(i * 10 + j)} h={i} v={j} /></td>);
} }
cells.push(<tr key={(i * 100000)}>{line}</tr>); cells.push(<tr key={(i * 100000)}>{line}</tr>);
} }

17
src/components/Ready.js Normal file
View File

@ -0,0 +1,17 @@
import { Component } from "react";
export default class Ready extends Component {
constructor(props) {
super(props);
this.state = {
text: "Расставь корабли чтобы активировать",
disabled: true
}
}
render() {
return <button className='main' disabled={this.state.disabled} onClick={this.goNewGame}><p>{this.state.text}</p></button>
}
}

View File

@ -1,3 +1,5 @@
import {Component} from 'react';
class Connect extends Component { class Connect extends Component {
} }

View File

@ -2,6 +2,7 @@ import React, { Component } from 'react';
import '../styles/styles.css'; import '../styles/styles.css';
import '../styles/bootstrap.css'; import '../styles/bootstrap.css';
import Field from '../components/Field.js'; import Field from '../components/Field.js';
import Ready from '../components/Ready.js';
import {host} from '../scripts/requests.js'; import {host} from '../scripts/requests.js';
class NewGame extends Component { class NewGame extends Component {
@ -19,19 +20,19 @@ class NewGame extends Component {
<div className='row'> <div className='row'>
<div className='col-1'> <div className='col-1'>
<p>Player1</p> <p>Player1</p>
<Field /> <Field parent={this} changeable={true} />
</div> </div>
<div className='col-5'></div> <div className='col-5'></div>
<div className='col-1'> <div className='col-1'>
<p>Player2</p> <p>Player2</p>
<Field /> <Field parent={this} changeable={false} />
</div> </div>
</div> </div>
<center> <center>
<p>Ссылка для подключения</p> <p>Ссылка для подключения</p>
<input className='borders' value={host + "connect?token=" + this.getToken()} /> <input className='borders' value={host + "connect?token=" + this.getToken()} />
</center> </center>
<button className='main' onClick={this.goNewGame}><p>Я готов</p></button> <Ready />
</div> </div>
); );
} }