Skip to content

Commit

Permalink
Displays time taken by each user .Also , supports Blitz chess
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran authored and kiran committed Jan 20, 2015
1 parent 9246a79 commit 2d63718
Show file tree
Hide file tree
Showing 4 changed files with 522 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

.idea
*.iml
45 changes: 45 additions & 0 deletions public/javascripts/chesshub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $( document ).ready(function() {
* This name is then passed to the socket connection handshake query
*/
var username;
var time_out=300;//5 minutes in seconds
if($("#loggedUser").length) {
username = $("#loggedUser").data("user");
} else {
Expand Down Expand Up @@ -133,6 +134,47 @@ $( document ).ready(function() {
var side = $("#board").data('side');
var opponentSide = side === "black" ? "white" : "black";

/*
* Timer : displays time taken by each player while making moves
*/
var timer=function(time_set)
{
if(true)
{
if(game.turn().toString()=='w')
{
time_set[0]+=1;
if(time_set[0]>time_out)
{
//handle time out
$('#gameResult').html('TimeOut! Black Won !');
$('#gameResultPopup').modal({
keyboard: false,
backdrop: 'static'
});
clearInterval(timer_interval);
}
$("#timew").html(("00" + Math.floor(time_set[0]/60)).slice (-2)+":"+("00" + time_set[0]%60).slice (-2));
}
if(game.turn().toString()=='b')
{
time_set[1]+=1;
if(time_set[1]>time_out)
{
//handle time out
$('#gameResult').html('TimeOut! White Won !');
$('#gameResultPopup').modal({
keyboard: false,
backdrop: 'static'
});
clearInterval(timer_interval);
}
$("#timeb").html(("00" + Math.floor(time_set[1]/60)).slice (-2)+":"+("00" + time_set[1]%60).slice (-2));
}
}
return time_set;
};

/*
* When a piece is dragged, check if it the current player has the turn
*/
Expand Down Expand Up @@ -217,6 +259,9 @@ $( document ).ready(function() {
* A second player has joined the game => the game can start
*/
socket.on('ready', function (data) {
//intialize the timer
var time_sets=[0,0];
timer_interval=setInterval(function(){ time_sets=timer(time_sets)}, 1000);//repeat every second
$('#turn-w').addClass("fa fa-spinner");
$('#player-white').html(data.white);
$('#player-black').html(data.black);
Expand Down
Loading

0 comments on commit 2d63718

Please sign in to comment.