diff --git a/app.js.jsx b/app.js.jsx
index 2dbfefd..3563a20 100644
--- a/app.js.jsx
+++ b/app.js.jsx
@@ -1,3 +1,9 @@
+// points deducted for each bad guess
+var BAD_SET_PENALTY = 50;
+// will be divided by average solve time in seconds
+//
+var TOP_SCORE = 60000;
+
window.App = React.createClass({
getInitialState: function () {
return {
@@ -5,18 +11,32 @@ window.App = React.createClass({
buildingSet: [],
showNotif: false,
notif: "",
- gameWon: false
- }
+ gameWon: false,
+ averageTime: ""
+ };
+ },
+
+ componentDidMount: function() {
+ this.startTime = Date.now();
+ this.bestTime = "";
+ // this.badSets = 0;
},
- gameWon: function () {
- if (this.state.setsFound.length == this.props.cards.solution.length) {
+ gameWon: function (setsFound) {
+ if (setsFound.length == this.props.cards.solution.length) {
return true;
} else {
return false;
}
},
+ calculateBestTime: function() {
+ if (this.bestTime === "" || this.state.averageTime < this.bestTime) {
+ this.bestTime = this.state.averageTime;
+ }
+ return this.bestTime;
+ },
+
checkCurrentSet: function () {
var set = this.state.buildingSet,
duplicate = false,
@@ -27,35 +47,39 @@ window.App = React.createClass({
duplicate = true;
isASet = false;
}
- })
+ });
this.handleCurrentSetStatus(isASet, duplicate);
},
handleCurrentSetStatus: function (status, dup) {
+ var notif;
+ var setsFound = this.state.setsFound;
+ var gameStatus = this.state.gameStatus;
if (status) {
- this.state.setsFound.push(this.state.buildingSet);
- var gameStatus = this.gameWon();
- this.setState({
- buildingSet: [],
- showNotif: true,
- notif: "Found a set!",
- gameWon: gameStatus
- });
+ setsFound.push(this.state.buildingSet);
+ gameStatus = this.gameWon(setsFound);
+ notif = "Found a set!";
+ this.updateScore();
} else {
- var notif;
if (dup) {
notif = "You already found that set.";
} else {
+ this.badSets ++;
notif = "That's not a set.";
}
-
- this.setState({
- buildingSet: [],
- showNotif: true,
- notif: notif
- });
}
+ this.setState({
+ buildingSet: [],
+ showNotif: true,
+ notif: notif,
+ setsFound: setsFound,
+ gameWon: gameStatus
+ });
+ },
+
+ updateScore: function() {
+ this.setState({averageTime: this.calculateScore()});
},
handleClick: function (cardValue) {
@@ -75,10 +99,30 @@ window.App = React.createClass({
this.forceUpdate();
},
+ calculateScore: function() {
+ var totalTime = (Date.now() - this.startTime) / 1000; // avg seconds per currently discovered set
+ console.log("total time: " + totalTime);
+ var avgTime = totalTime / this.state.setsFound.length;
+ console.log(avgTime);
+ return avgTime;
+ },
+
+ lastFinishTimeInSeconds: function() {
+ var latestTime = (Date.now() - this.startTime) / 1000;
+ this.startTime = Date.now();
+ return latestTime;
+ },
+
renderModal: function () {
if (this.state.gameWon) {
startParade();
- return