Permalink
Browse files

score and time card

  • Loading branch information...
1 parent 4afa99b commit 1bb8f572fe59f57d900dae3a5009138d036e0c43 @deepak1556 deepak1556 committed Dec 1, 2012
Showing with 47 additions and 1 deletion.
  1. +18 −1 server.js
  2. +29 −0 static/script.js
View
@@ -40,14 +40,31 @@ app.configure( function () {
});
});
+var start_time = "2:00";
+var minute = parseInt(start_time.split(":")[0])*60;
+var second = parseInt(start_time.split(":")[1]);
+var previous_correct_word_time = (minute+second);
+var current_time = previous_correct_word_time;
+var score = 0;
+var game_status = 0;
+
io.sockets.on('connection', function(socket) {
console.log("Connected boopathi" + socket);
var game = new wordament();
socket.emit('question', { question: game.question.split(',').splice(0,4) });
+ socket.emit('timer', { start : start_time.split(":")});
+ game_status=1;
+ var timer = setInterval(function(){current_time=current_time-1;if(current_time==0){clearInterval(timer);game_status=0;}},1000);
socket.on('answer', function(answer) {
+ if(game_status){
+ if(game.search(answer)){
+ score= (score+Math.floor(1000/(previous_correct_word_time-current_time)))*answer.length;
+ previous_correct_word_time=current_time;
+ }
+ }
socket.emit('result', {
correct: game.search(answer),
- answer: answer,
+ score : score
});
});
});
View
@@ -66,6 +66,30 @@ var Queue = {
},
}
+var countdown = function(value){
+ this.minute = value[0];
+ this.second = value[1];
+};
+
+countdown.prototype.tick = function(){
+ if(this.second > 0 || this.minute > 0){
+ this.second = this.second-1;
+ if(this.second == 0){
+ this.minute = this.minute-1;
+ this.second = 59;
+ }
+ this.update();
+ }
+ else
+ clearInterval(set);
+};
+
+countdown.prototype.update = function(){
+ var seconds = this.second;
+ if(seconds<10) seconds = "0" + seconds;
+ $("#answer").val(this.minute + ":" + seconds);
+};
+
$( function() {
var socket = io.connect("http://"+window.location.hostname);
@@ -78,6 +102,11 @@ $( function() {
}
}
});
+ //timerbug to fix
+ socket.on('timer',function(data) {
+ countdown(data.start);
+ var set = setInterval(countdown.tick(),1000);
+ });
socket.on('result', function(data) {
if(data.correct) {
Queue.append(data.answer);

0 comments on commit 1bb8f57

Please sign in to comment.