Permalink
Browse files

Merge branch 'master' of github.com:heisenbuggers/game-off-2012

  • Loading branch information...
2 parents 1a48ba6 + 4d3a1e4 commit 2d22fd0b723dd76b9169a4389e6b6a9de8c135b9 @boopathi boopathi committed Dec 6, 2012
Showing with 68 additions and 1 deletion.
  1. +18 −1 server.js
  2. +35 −0 static/script.js
  3. +13 −0 static/style.css
  4. +2 −0 views/index.ejs
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 wordfs();
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,35 @@ var Queue = {
},
}
+var countdown = function(value){
+ this.minute = value[0];
+ this.second = value[1]+1;
+};
+
+countdown.prototype.init = function(){
+ var self = this;
+ var set = setInterval(function(){self.tick();},1000);
+};
+
+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;
+ $("#timer").val(this.minute + ":" + seconds);
+};
+
$( function() {
var socket = io.connect("http://"+window.location.hostname);
@@ -78,6 +107,11 @@ $( function() {
}
}
});
+ //timer
+ socket.on('timer',function(data) {
+ var time = new countdown(data.start);
+ time.init();
+ });
socket.on('result', function(data) {
if(data.correct) {
Queue.append(data.answer);
@@ -86,6 +120,7 @@ $( function() {
backgroundColor: "#000"
},750);
Board.unselectall();
+ $("#score").val(data.score);
}
else $("#answer").css("background","#500").stop().animate({
backgroundColor: "#000"
View
@@ -68,3 +68,16 @@ body {
color: white;
border: 0;
}
+
+#timer,#score {
+ width: 100px;
+ margin: 0;
+ margin-top: 40px;
+ letter-spacing: 4px;
+ padding: 15px;
+ font-size: 20px;
+ outline: none;
+ background: black;
+ color: white;
+ border: 0;
+}
View
@@ -14,6 +14,8 @@
</div>
<div class="right circularbg">
<div id="queueContainer">
+ <input type="text" id="timer" />
+ <input type="text" id="score" />
<h3>Found: </h3>
<ul id="queue">
</ul>

0 comments on commit 2d22fd0

Please sign in to comment.