diff --git a/src/BoatGame.js b/src/BoatGame.js
index d48a65781..323cf1542 100644
--- a/src/BoatGame.js
+++ b/src/BoatGame.js
@@ -15,21 +15,6 @@ class BoatGame extends Component{
this.cache = new LocalStorageCache();
this.gameService = new GameService();
- this.endGames=this.endGames.bind(this)
- this.exitMainPage=this.exitMainPage.bind(this)
- this.incrementDifficulty=this.incrementDifficulty.bind(this)
- this.totalTime=this.totalTime.bind(this)
- this.showStatspage=this.showStatspage.bind(this)
- this.parse=this.parse.bind(this)
- this.cleanContent=this.cleanContent.bind(this)
- this.playAgain=this.playAgain.bind(this)
- this.setTotalWords=this.setTotalWords.bind(this)
- this.limitWords=this.limitWords.bind(this)
- this.setInitContent=this.setInitContent.bind(this)
- this.setLimitedContent=this.setLimitedContent.bind(this)
- this.assignPlayerPlace=this.assignPlayerPlace.bind(this)
- this.recordHighScore = this.recordHighScore.bind(this);
-
this.state={
isPlayerReady:false,
beginCountDown:false,
@@ -41,6 +26,7 @@ class BoatGame extends Component{
originalContent:"",
content:"",
accuracy:0,
+ timeOutInstance:0,
gameStart:false,
playerPlace:0,
playerDifficulty:1,
@@ -50,6 +36,8 @@ class BoatGame extends Component{
username: this.cache.get("username"),
headerLinks: ["Stats" ,"Games", "Learn", "Home"],
};
+
+
}
async recordHighScore() {
@@ -70,10 +58,13 @@ class BoatGame extends Component{
this.setInitContent(data.games.boatrace[randIndex])
}
+ componentWillUnmount = () => {
+ clearTimeout(this.state.timeOutInstance)
+ }
exitMainPage = (difficulty) => {
- var diffString = difficulty
- var diffNum = 1
+ let diffString = difficulty
+ let diffNum = 1
if( diffString === "easy" ){
diffNum = 1
@@ -198,7 +189,7 @@ class BoatGame extends Component{
}
totalTime = (time) => {
- var minutes=time/60
+ let minutes=time/60
this.setState({totalMinutes:minutes})
}
@@ -206,20 +197,26 @@ class BoatGame extends Component{
this.setState({playerPlace:position})
}
- endGames= (state, time) => {
- var minutes=time/60
- var totalChars= state.incorrect.length + state.correct.length
- var playerAccuracy= Math.floor((1- state.incorrect.length/totalChars)*100)
- var wpm = Math.floor(totalChars/(5*minutes))
- this.setState({showSign:true,inputOff:true})
- setTimeout(() => {
- this.setState({
+ initiateTimeOut = (playerAccuracy,wpm) => {
+ return setTimeout(() => {
+ this.setState({
playerHasLost:true,
isPlayerReady:false,
gameStart:false,
accuracy:playerAccuracy,
- wordsPerMinute:wpm,
- })},6000)
+ wordsPerMinute:wpm
+ })
+ }, 6000);
+ }
+
+ endGames= (state, time) => {
+ let minutes=time/60
+ let totalChars= state.incorrect.length + state.correct.length
+ let playerAccuracy= Math.floor((1- state.incorrect.length/totalChars)*100)
+ let wpm = Math.floor(totalChars/(5*minutes))
+ this.setState({showSign:true,inputOff:true})
+
+ this.setState({timeOutInstance:this.initiateTimeOut(playerAccuracy,wpm)})
}
showStatspage = () => {
diff --git a/src/CocoType.js b/src/CocoType.js
deleted file mode 100644
index 6dfe30703..000000000
--- a/src/CocoType.js
+++ /dev/null
@@ -1,136 +0,0 @@
-import React, { Component } from 'react';
-import ShowSpinner from './components/spinner';
-import './style/CocoType.css'
-import styled from 'styled-components';
-
-
-const GameText = styled.div`
- margin-top:4vh;
- height: 10vh;
- width: 80vw;
- border: 5px solid #F5A623;
- border-radius: 10px;
- background-color: #FFFFFF;
- font-size: 3.5rem;
- display:flex;
- justify-content:center;
-
-`
-
-class CocoType extends Component {
- constructor(props) {
- super(props);
- this.typeString=this.typeString.bind(this)
- this.updateIndex=this.updateIndex.bind(this)
- this.updateString=this.updateString.bind(this)
- this.updateLevel=this.updateLevel.bind(this)
- this.back=this.back.bind(this)
- this.state ={
- headerLinks: ["Stats" ,"Games", "Learn", "Home"],
- Time:"00:15",
- currLine:"",
- currLinenum:0,
- fullText:this.props.fullText,
- currChar:"",
- Level:1,
- Streak:0,
- indexptr:0,
- LongestStreak:0
- }
- }
-
-
- onKeyPressed = (e) => {
- let currindex= this.state.indexptr
- let isRightKey =e.key;
- if(isRightKey=="Shift"){
- console.log("Waiting for input to uppercase")
- }else if(isRightKey=="Backspace"){
- this.setState({Streak:0})
- this.back()
- }else if(isRightKey == this.state.currChar){
- console.log(true)
- this.setState({Streak:this.state.Streak + 1})
- this.updateIndex()
- }else{
- console.log(false)
- if(this.state.LongestStreak <= this.state.Streak){
- this.setState({LongestStreak:this.state.Streak})
- }
- this.setState({Streak:0})
- this.updateIndex()
- }
- };
-
- updateIndex(){
- var newIndex=this.state.indexptr;
- var newIndex= newIndex +1;
- this.setState({indexptr:newIndex})
- this.setState({currChar:this.state.currLine[newIndex]})
- if(newIndex==this.state.currLine.length){
- this.updateString()
- }
-
- }
- back(){
- if(this.state.indexptr == 0){
- this.setState({currChar:this.state.currLine[0]})
- }
- var newIndex= this.state.indexptr-1
- this.setState({indexptr:newIndex, currChar:this.state.currLine[newIndex]})
- }
-
- updateString()
- {
- var nextLinenum = this.state.currLinenum + 1
- this.setState({currLinenum:nextLinenum, indexptr:0})
- this.typeString()
- }
-
- typeString(){
- var lines= this.state.fullText.split("\n")
- console.log(this.state.currLinenum)
- console.log(lines.length)
- if(this.state.currLinenum > lines.length-1){
- this.updateLevel()
- }
- var nextLine= lines[this.state.currLinenum].trim()
- this.setState({currLine:nextLine,currChar:nextLine[this.state.indexptr]})
- };
-
- updateLevel(){
-
- }
-
- componentDidMount() {
- this.typeString()
- document.addEventListener('keydown', this.onKeyPressed);
- }
-
- componentWillUnmount() {
- document.removeEventListener('keydown', this.onKeyPressed);
- }
-
- render() {
- const {
- isLoading,
- } = this.props;
-
-
- if(isLoading) {
- return