Skip to content

Commit a15f2d5

Browse files
committed
Add checkchances and updatePlay functions
Relates #13
1 parent 164ef21 commit a15f2d5

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

components/app/app.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ export default class App extends React.Component {
77
playing: true,
88
}
99

10+
updatePlay = () => {
11+
this.setState((prevState) => {
12+
console.log("UpdatePlay reached");
13+
return {
14+
playing: !prevState.playing
15+
}
16+
})
17+
}
18+
1019
render() {
11-
12-
return (
13-
<React.Fragment>
14-
<Title />
15-
<Game />
16-
</React.Fragment>
17-
)
20+
21+
return (
22+
<React.Fragment>
23+
<Title />
24+
<Game updatePlay={this.updatePlay} />
25+
</React.Fragment>
26+
)
27+
}
1828
}
19-
}
2029

2130

components/game/game.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ export default class Game extends React.Component {
4040
return {
4141
chances: prevState.chances - 1,
4242
}
43-
})
43+
}, this.checkChances)
44+
}
45+
}
46+
47+
checkChances = () => {
48+
const chances = this.state.chances;
49+
if (chances == 0){
50+
this.props.updatePlay();
4451
}
45-
4652
}
4753

4854
render() {

0 commit comments

Comments
 (0)