done
This commit is contained in:
parent
628c2b932e
commit
056cbd0ef7
@ -43,7 +43,8 @@ class Cell extends Component {
|
|||||||
|
|
||||||
shoot() {
|
shoot() {
|
||||||
this.props.parent.setState({
|
this.props.parent.setState({
|
||||||
changeable: false
|
changeable: false,
|
||||||
|
text: "Подожди"
|
||||||
})
|
})
|
||||||
request("shoot", {
|
request("shoot", {
|
||||||
game_id: localStorage.getItem("gameId"),
|
game_id: localStorage.getItem("gameId"),
|
||||||
@ -65,7 +66,6 @@ class Cell extends Component {
|
|||||||
|
|
||||||
click() {
|
click() {
|
||||||
if (!this.state.changeable) return;
|
if (!this.state.changeable) return;
|
||||||
if (this.state.shotState !== " ") return;
|
|
||||||
if (this.props.parent.props.ready)
|
if (this.props.parent.props.ready)
|
||||||
this.shoot();
|
this.shoot();
|
||||||
else
|
else
|
||||||
@ -80,6 +80,8 @@ class Cell extends Component {
|
|||||||
color = "darkcyan";
|
color = "darkcyan";
|
||||||
} else if (this.state.shotState === ".") {
|
} else if (this.state.shotState === ".") {
|
||||||
color = "gray";
|
color = "gray";
|
||||||
|
} else if (this.symb === "o") {
|
||||||
|
color = "green";
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<button style={{backgroundColor: color}} onClick={() => this.click()} className="cell"></button>
|
<button style={{backgroundColor: color}} onClick={() => this.click()} className="cell"></button>
|
||||||
|
@ -9,7 +9,8 @@ class Game extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
myField: null,
|
myField: null,
|
||||||
opponentField: null,
|
opponentField: null,
|
||||||
myTurn: false
|
myTurn: false,
|
||||||
|
text: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +20,15 @@ class Game extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
myField: response.my_field,
|
myField: response.my_field,
|
||||||
opponentField: response.opponent_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", {
|
request("get_fields", {
|
||||||
game_id: localStorage.getItem("gameId"),
|
game_id: localStorage.getItem("gameId"),
|
||||||
@ -29,7 +37,7 @@ class Game extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.timer = setInterval(() => this.doUpdate(), 2000);
|
this.timer = setInterval(() => this.doUpdate(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -41,7 +49,11 @@ class Game extends Component {
|
|||||||
<p>Player1</p>
|
<p>Player1</p>
|
||||||
<Field cells={this.state.myField} parent={this} changeable={false} ready={false} />
|
<Field cells={this.state.myField} parent={this} changeable={false} ready={false} />
|
||||||
</div>
|
</div>
|
||||||
<div className='col-5'></div>
|
<div className='col-5'>
|
||||||
|
<p>
|
||||||
|
{this.state.text}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div className='col-1'>
|
<div className='col-1'>
|
||||||
<p>Player2</p>
|
<p>Player2</p>
|
||||||
<Field cells={this.state.opponentField} parent={this} changeable={this.state.myTurn} ready={true} />
|
<Field cells={this.state.opponentField} parent={this} changeable={this.state.myTurn} ready={true} />
|
||||||
|
@ -20,8 +20,6 @@ class Home extends Component {
|
|||||||
<center><p className='logo'><b>Sprint Battleship</b></p></center>
|
<center><p className='logo'><b>Sprint Battleship</b></p></center>
|
||||||
</div>
|
</div>
|
||||||
<button className='main' onClick={() => this.goNewGame()}><p>Новая игра</p></button>
|
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -94,17 +94,6 @@ class NewGame extends Component {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<center><p className='logo'>Расставь корабли</p></center>
|
<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='row'>
|
||||||
<div className='col-1'>
|
<div className='col-1'>
|
||||||
<p>Player1</p>
|
<p>Player1</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user