-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.EightQueens-timer { | ||
border: 1px solid #988010; | ||
background-color: #fcebb4; | ||
color: black; | ||
margin-top: 8px; | ||
padding: 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Eight Queens chess game | ||
* Timer box | ||
*/ | ||
import React, { Component } from 'react'; | ||
import './Timer.css'; | ||
|
||
class Timer extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
currentTime: new Date().valueOf(), | ||
startTime: new Date().valueOf(), | ||
}; | ||
|
||
this.tick = this.tick.bind(this) | ||
} | ||
|
||
componentDidMount(){ | ||
this.timer = setInterval(this.tick, 1000) | ||
} | ||
|
||
componentWillUnmount(){ | ||
clearInterval(this.timer); | ||
} | ||
|
||
tick() { | ||
this.setState({ currentTime: new Date().valueOf() }); | ||
} | ||
|
||
render() { | ||
if (this.props.gameStatus === 'solved') { | ||
clearInterval(this.timer); | ||
} | ||
|
||
const seconds = Math.floor((this.state.currentTime - this.state.startTime) / 1000); | ||
//const minutes = Math.floor(seconds/60); | ||
//const hours = Math.floor(minutes/60); | ||
//const days = Math.floor(hours/24); | ||
|
||
return ( | ||
<div className="EightQueens-timer"> | ||
<small>{this.props.gameStatus} </small> | ||
{seconds} | ||
<small> seconds</small> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Timer; |