-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathBoggle.js
59 lines (53 loc) · 1.43 KB
/
MathBoggle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react'
import ScoreTracker from './math-boggle/ScoreTracker'
import TimeTracker from './math-boggle/TimeTracker'
import GameBoard from './math-boggle/GameBoard'
class MathBoggle extends React.Component {
constructor(){
super()
this.state = {
score: 0,
playing: false
}
this.addToScore = this.addToScore.bind(this)
this.onCountdownComplete = this.onCountdownComplete.bind(this)
this.playMathBoggle = this.playMathBoggle.bind(this)
}
onCountdownComplete(){
this.playMathBoggle(false)
}
addToScore(scoreToAdd){
this.setState({
score: this.state.score + scoreToAdd
})
}
playMathBoggle(isPlaying){
this.setState({playing: isPlaying})
if(isPlaying){
this.setState({score: 0})
}
}
render(){
return (
<div>
<div className="math-boggle">
<TimeTracker
isPlaying={this.state.playing}
totalTime={360}
onCountdownComplete={this.onCountdownComplete}/>
<ScoreTracker
score={this.state.score} />
<button
className="button play green"
disabled={this.state.playing}
onClick={this.playMathBoggle.bind(this, true)} >Play</button>
<GameBoard
score={this.state.score}
addToScore={this.addToScore}
isPlaying={this.state.playing} />
</div>
</div>
)
}
}
export default MathBoggle