This commit is contained in:
Administrator 2022-08-28 16:30:44 +03:00
parent 628c2b932e
commit 056cbd0ef7
4 changed files with 20 additions and 19 deletions

View File

@ -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 (
<button style={{backgroundColor: color}} onClick={() => this.click()} className="cell"></button>

View File

@ -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 {
<p>Player1</p>
<Field cells={this.state.myField} parent={this} changeable={false} ready={false} />
</div>
<div className='col-5'></div>
<div className='col-5'>
<p>
{this.state.text}
</p>
</div>
<div className='col-1'>
<p>Player2</p>
<Field cells={this.state.opponentField} parent={this} changeable={this.state.myTurn} ready={true} />

View File

@ -20,8 +20,6 @@ class Home extends Component {
<center><p className='logo'><b>Sprint Battleship</b></p></center>
</div>
<button className='main' onClick={() => this.goNewGame()}><p>Новая игра</p></button>
<div className='space'></div>
<button className='main' onClick={() => window.location.href="/connect"}><p>Присоединиться</p></button>
</div>
);
}

View File

@ -94,17 +94,6 @@ class NewGame extends Component {
return (
<div>
<center><p className='logo'>Расставь корабли</p></center>
{/* <div className='row'>
<div className='col-1'>
<p>Player1</p>
<Field parent={this} changeable={true} />
</div>
<div className='col-5'></div>
<div className='col-1'>
<p>Player2</p>
<Field parent={this} changeable={false} />
</div>
</div> */}
<div className='row'>
<div className='col-1'>
<p>Player1</p>