Client/JavaScript/game.js
// the function that prints the messages send by the players
the function that prints the messages send by the players
the function that prints the messages send by the players
function printMessage(text, playerIndex) {
	var player;
	if(game.players.length == 2 && playerIndex == game.you) player = 0;
	else if(game.players.length == 2) player=2;
	else player = (4+(playerIndex-game.you))%4;
	var textbox;
	var circle1;
	var circle2; 
	if(messageDisplayed[player]==0 && !fadeOutInProgress) { 
		textbox = $("div#textbox_"+(player+1));
		circle1 = $("div#circle1_"+(player+1));
		circle2 = $("div#circle2_"+(player+1));
		var message = $("<p>").text(text);
		textbox.prepend(message);
		textbox.fadeIn();
		circle1.fadeIn();
		circle2.fadeIn();
	}
	else if(messageDisplayed[player]==0) {
		textbox = $("div#textbox_"+(player+1));
		circle1 = $("div#circle1_"+(player+1));
		circle2 = $("div#circle2_"+(player+1));
		textbox.stop(true, false);
		circle1.stop(true, false);
		circle2.stop(true, false);
		fadeOutInProgress = false;
		$(textbox).text("");
		var message = $("<p>").text(text);
		textbox.prepend(message);
		textbox.fadeIn();
		circle1.fadeIn();
		circle2.fadeIn();
	}
	else {
		textbox = $("#textbox_"+(player+1));
		circle1 = $("#circle1_"+(player+1));
		circle2 = $("#circle2_"+(player+1));
		var message = $("<p>").text(text);
		message.hide();
		textbox.prepend(message);
		message.fadeIn();
	}
	messageDisplayed[player]++;
	setTimeout(function() {
		if(message.parent().length > 0) {
			messageDisplayed[player]--;
			if(messageDisplayed[player]==0) {
				fadeOutInProgress = true;
				$(circle1).fadeOut("normal");
				$(circle2).fadeOut("normal");
				$(textbox).fadeOut("normal", function() { 
					$(textbox).text("");
					fadeOutInProgress=false;
				});
			} else{			
				message.fadeOut();
			}
		}
	}, 6500);
}
function printMessage ( text , playerIndex ) { var player ; if ( game . players . length == 2 && playerIndex == game . you ) player = 0 ; else if ( game . players . length == 2 ) player = 2 ; else player = ( 4 + ( playerIndex - game . you ) ) % 4 ; var textbox ; var circle1 ; var circle2 ; if ( messageDisplayed [ player ] == 0 && ! fadeOutInProgress ) { textbox = $ ( "div#textbox_" + ( player + 1 ) ) ; circle1 = $ ( "div#circle1_" + ( player + 1 ) ) ; circle2 = $ ( "div#circle2_" + ( player + 1 ) ) ; var message = $ ( "<p>" ) . text ( text ) ; textbox . prepend ( message ) ; textbox . fadeIn ( ) ; circle1 . fadeIn ( ) ; circle2 . fadeIn ( ) ; } else if ( messageDisplayed [ player ] == 0 ) { textbox = $ ( "div#textbox_" + ( player + 1 ) ) ; circle1 = $ ( "div#circle1_" + ( player + 1 ) ) ; circle2 = $ ( "div#circle2_" + ( player + 1 ) ) ; textbox . stop ( true , false ) ; circle1 . stop ( true , false ) ; circle2 . stop ( true , false ) ; fadeOutInProgress = false ; $ ( textbox ) . text ( "" ) ; var message = $ ( "<p>" ) . text ( text ) ; textbox . prepend ( message ) ; textbox . fadeIn ( ) ; circle1 . fadeIn ( ) ; circle2 . fadeIn ( ) ; } else { textbox = $ ( "#textbox_" + ( player + 1 ) ) ; circle1 = $ ( "#circle1_" + ( player + 1 ) ) ; circle2 = $ ( "#circle2_" + ( player + 1 ) ) ; var message = $ ( "<p>" ) . text ( text ) ; message . hide ( ) ; textbox . prepend ( message ) ; message . fadeIn ( ) ; } messageDisplayed [ player ] ++ ; setTimeout ( function ( ) { if ( message . parent ( ) . length > 0 ) { messageDisplayed [ player ] -- ; if ( messageDisplayed [ player ] == 0 ) { fadeOutInProgress = true ; $ ( circle1 ) . fadeOut ( "normal" ) ; $ ( circle2 ) . fadeOut ( "normal" ) ; $ ( textbox ) . fadeOut ( "normal" , function ( ) { $ ( textbox ) . text ( "" ) ; fadeOutInProgress = false ; } ) ; } else { message . fadeOut ( ) ; } } } , 6500 ) ; }
the function that prints the messages send by the players
the function that prints the messages send by the players