2012-02-06 22:00:24 +00:00
|
|
|
/*
|
2012-02-02 22:47:23 +00:00
|
|
|
* Copyright (c) 2012, Andy Janata
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
|
|
* provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
|
|
* and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
|
|
* conditions and the following disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
|
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-01-22 01:34:18 +00:00
|
|
|
/**
|
|
|
|
* Class to manage the game interface.
|
|
|
|
*
|
2012-02-06 22:00:24 +00:00
|
|
|
* @author Andy Janata (ajanata@socialgamer.net)
|
2012-02-20 20:34:26 +00:00
|
|
|
* @param {Number}
|
2012-01-22 01:34:18 +00:00
|
|
|
* id The game id.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
cah.Game = function(id) {
|
|
|
|
/**
|
|
|
|
* The game id.
|
|
|
|
*
|
2012-02-20 20:34:26 +00:00
|
|
|
* @type {Number}
|
2012-01-22 01:34:18 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.id_ = id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The element for this game lobby.
|
|
|
|
*
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.element_ = $("#game_template").clone()[0];
|
2012-01-23 23:06:20 +00:00
|
|
|
this.element_.id = "game_" + id;
|
2012-01-23 07:58:36 +00:00
|
|
|
$(this.element_).removeClass("hide");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The element for the scoreboard for this game.
|
|
|
|
*
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.scoreboardElement_ = $("#scoreboard_template").clone()[0];
|
2012-01-23 23:06:20 +00:00
|
|
|
this.scoreboardElement_.id = "scoreboard_" + id;
|
2012-01-23 07:58:36 +00:00
|
|
|
$(this.scoreboardElement_).removeClass("hide");
|
2013-06-12 11:04:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The first spectator element within the scoreboard.
|
|
|
|
*
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.firstSpectatorElement_ = null;
|
2012-01-23 07:58:36 +00:00
|
|
|
|
2012-12-30 05:03:45 +00:00
|
|
|
/**
|
|
|
|
* The element for the chat room for this game
|
2013-02-25 02:47:05 +00:00
|
|
|
*
|
2012-12-30 05:03:45 +00:00
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
2013-02-25 02:47:05 +00:00
|
|
|
this.chatElement_ = $("#tab-global").clone()[0];
|
|
|
|
this.chatElement_.id = "tab-chat-game_" + this.id_;
|
|
|
|
$(".chat_submit", this.chatElement_).click(chatsubmit_click(this.id_, this.chatElement_));
|
|
|
|
$(".chat", this.chatElement_).keyup(chat_keyup($(".chat_submit", this.chatElement_)));
|
|
|
|
// TODO make it not even copy this in the first place
|
|
|
|
$(".log", this.chatElement_).empty();
|
2012-12-30 05:03:45 +00:00
|
|
|
|
2012-03-15 20:50:42 +00:00
|
|
|
/**
|
|
|
|
* The element for the game options for this game.
|
|
|
|
*
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.optionsElement_ = $("#game_options_template").clone()[0];
|
|
|
|
this.optionsElement_.id = "game_options_" + id;
|
2013-04-06 22:30:12 +01:00
|
|
|
// TODO: It looks like I'm not changing the id on the label elements...
|
2012-03-15 20:50:42 +00:00
|
|
|
$("#score_limit_template_label", this.optionsElement_).attr("for", "score_limit_" + id);
|
|
|
|
$("#player_limit_template_label", this.optionsElement_).attr("for", "player_limit_" + id);
|
2013-06-10 12:36:11 +01:00
|
|
|
$("#spectator_limit_template_label", this.optionsElement_).attr("for", "spectator_limit_" + id);
|
2012-03-16 03:06:23 +00:00
|
|
|
$("#card_set_template_label", this.optionsElement_).attr("for", "card_set_" + id);
|
2012-03-19 04:20:48 +00:00
|
|
|
$("#game_password_template_label", this.optionsElement_).attr("for", "game_password_" + id);
|
2013-04-06 22:30:12 +01:00
|
|
|
$("#game_hide_password_template_label", this.optionsElement_).attr("for",
|
|
|
|
"game_hide_password_" + id);
|
2013-04-13 18:39:38 +01:00
|
|
|
$("#use_timer_template_label", this.optionsElement_).attr("for", "use_timer_" + id);
|
2012-03-19 04:20:48 +00:00
|
|
|
|
2012-03-15 20:50:42 +00:00
|
|
|
$("#score_limit_template", this.optionsElement_).attr("id", "score_limit_" + id);
|
|
|
|
$("#player_limit_template", this.optionsElement_).attr("id", "player_limit_" + id);
|
2013-06-10 12:36:11 +01:00
|
|
|
$("#spectator_limit_template", this.optionsElement_).attr("id", "spectator_limit_" + id);
|
2012-03-16 03:06:23 +00:00
|
|
|
$("#card_set_template", this.optionsElement_).attr("id", "card_set_" + id);
|
2012-03-19 04:20:48 +00:00
|
|
|
$("#game_password_template", this.optionsElement_).attr("id", "game_password_" + id);
|
2013-04-06 22:30:12 +01:00
|
|
|
$("#game_fake_password_template", this.optionsElement_).attr("id", "game_fake_password_" + id);
|
|
|
|
$("#game_hide_password_template", this.optionsElement_).attr("id", "game_hide_password_" + id);
|
2013-04-13 18:39:38 +01:00
|
|
|
$("#use_timer_template", this.optionsElement_).attr("id", "use_timer_" + id);
|
2012-03-19 04:20:48 +00:00
|
|
|
|
2013-04-28 07:10:56 +01:00
|
|
|
for ( var key in cah.CardSet.byWeight) {
|
2012-07-07 23:01:33 +01:00
|
|
|
/** @type {cah.CardSet} */
|
2013-04-28 07:10:56 +01:00
|
|
|
var cardSet = cah.CardSet.byWeight[key];
|
2012-07-07 23:01:33 +01:00
|
|
|
var cardSetElementId = 'card_set_' + this.id_ + '_' + cardSet.getId();
|
2013-03-27 00:19:01 +00:00
|
|
|
var title = cardSet.getDescription() + ' ' + cardSet.getBlackCardCount() + ' black card'
|
2012-07-07 23:01:33 +01:00
|
|
|
+ (cardSet.getBlackCardCount() == 1 ? '' : 's') + ', ' + cardSet.getWhiteCardCount()
|
2013-03-27 00:19:01 +00:00
|
|
|
+ ' white card' + (cardSet.getWhiteCardCount() == 1 ? '' : 's') + '.';
|
2013-04-20 20:21:28 +01:00
|
|
|
var aria_label = cardSet.getName() + '. ' + title;
|
2013-03-27 03:31:46 +00:00
|
|
|
// that space at the beginning matters
|
|
|
|
var html = ' <span class="nowrap"><input type="checkbox" id="' + cardSetElementId
|
|
|
|
+ '" class="card_set" title="' + title + '" value="' + cardSet.getId()
|
2013-04-20 20:21:28 +01:00
|
|
|
+ '" name="card_set" aria-label="' + aria_label + '" /><label for="' + cardSetElementId
|
|
|
|
+ '" title="' + title + '" class="card_set_label">' + cardSet.getName() + '</label></span>';
|
2012-07-07 23:01:33 +01:00
|
|
|
if (cardSet.isBaseDeck()) {
|
|
|
|
$(".base_card_sets", this.optionsElement_).append(html);
|
|
|
|
} else {
|
|
|
|
$(".extra_card_sets", this.optionsElement_).append(html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 20:50:42 +00:00
|
|
|
$("label", this.optionsElement_).removeAttr("id");
|
|
|
|
$(".game_options", this.element_).replaceWith(this.optionsElement_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nickname of the host of this game.
|
|
|
|
*
|
|
|
|
* @type {String}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.host_ = "";
|
|
|
|
|
2012-01-23 07:58:36 +00:00
|
|
|
/**
|
|
|
|
* User->value mapping of scorecards in the scoreboard.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.scoreCards_ = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The cards in the player's hand.
|
|
|
|
*
|
|
|
|
* @type {Array}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.hand_ = Array();
|
2012-01-23 21:20:15 +00:00
|
|
|
|
2012-01-27 23:41:57 +00:00
|
|
|
/**
|
2012-02-01 01:59:53 +00:00
|
|
|
* Map of id to card object arrays for round cards.
|
2012-01-27 23:41:57 +00:00
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.roundCards_ = {};
|
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
/**
|
|
|
|
* The game's state.
|
|
|
|
*
|
|
|
|
* @type {cah.$.GameState}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.state_ = cah.$.GameState.LOBBY;
|
|
|
|
|
|
|
|
/**
|
2012-02-08 03:30:30 +00:00
|
|
|
* The black card for the current round.
|
2012-01-25 00:20:43 +00:00
|
|
|
*
|
|
|
|
* @type {cah.card.BlackCard}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.blackCard_ = null;
|
|
|
|
|
2012-02-08 03:30:30 +00:00
|
|
|
/**
|
|
|
|
* The black card for the previous round.
|
|
|
|
*
|
|
|
|
* @type {cah.card.BlackCard}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.lastBlackCard_ = null;
|
|
|
|
|
2012-01-25 06:39:19 +00:00
|
|
|
/**
|
|
|
|
* Selected card from the player's hand.
|
|
|
|
*
|
|
|
|
* @type {cah.card.WhiteCard}
|
|
|
|
* @private;
|
|
|
|
*/
|
|
|
|
this.handSelectedCard_ = null;
|
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
/**
|
|
|
|
* Selected card from the round's white cards.
|
|
|
|
*
|
|
|
|
* @type {cah.card.WhiteCard}
|
|
|
|
* @private;
|
|
|
|
*/
|
|
|
|
this.roundSelectedCard_ = null;
|
|
|
|
|
2012-01-25 06:39:19 +00:00
|
|
|
/**
|
2012-02-08 00:31:56 +00:00
|
|
|
* The name of the judge of the current round.
|
2012-01-25 06:39:19 +00:00
|
|
|
*
|
|
|
|
* @type {String}
|
|
|
|
* @private
|
|
|
|
*/
|
2012-01-27 02:07:39 +00:00
|
|
|
this.judge_ = null;
|
2012-01-27 08:14:48 +00:00
|
|
|
|
2012-01-25 08:03:41 +00:00
|
|
|
/**
|
|
|
|
* Scale factor for hand cards when zoomed out.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.handCardSmallScale_ = .35;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale factor for hand cards when zoomed in.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.handCardLargeScale_ = .6;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size for hand cards when zoomed out.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.handCardSmallSize_ = 83;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size for hand cards when zoomed in.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.handCardLargeSize_ = 142;
|
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
/**
|
|
|
|
* Scale factor for round cards when zoomed out.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.roundCardSmallScale_ = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale factor for round cards when zoomed in.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.roundCardLargeScale_ = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size for round cards when zoomed out.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.roundCardSmallSize_ = 236;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size for round cards when zoomed in.
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.roundCardLargeSize_ = 236;
|
|
|
|
|
2012-02-08 03:30:30 +00:00
|
|
|
/**
|
|
|
|
* Whether we are showing the result of the last round.
|
|
|
|
*
|
|
|
|
* @type {Boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.showingLastRound_ = false;
|
|
|
|
|
2012-03-19 04:38:24 +00:00
|
|
|
/**
|
|
|
|
* Whether we are showing the options or the game.
|
|
|
|
*
|
|
|
|
* @type {Boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.showingOptions_ = true;
|
|
|
|
|
2012-01-23 21:20:15 +00:00
|
|
|
$("#leave_game").click(cah.bind(this, this.leaveGameClick_));
|
|
|
|
$("#start_game").click(cah.bind(this, this.startGameClick_));
|
2012-01-25 06:39:19 +00:00
|
|
|
$(".confirm_card", this.element_).click(cah.bind(this, this.confirmClick_));
|
2012-02-08 03:30:30 +00:00
|
|
|
$(".game_show_last_round", this.element_).click(cah.bind(this, this.showLastRoundClick_));
|
2012-03-19 04:38:24 +00:00
|
|
|
$(".game_show_options", this.element_).click(cah.bind(this, this.showOptionsClick_));
|
2012-03-19 04:20:48 +00:00
|
|
|
$("select", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
|
|
|
$("input", this.optionsElement_).blur(cah.bind(this, this.optionChanged_));
|
2013-04-13 18:39:38 +01:00
|
|
|
$(".use_timer", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
2012-07-07 23:01:33 +01:00
|
|
|
$(".card_set", this.optionsElement_).change(cah.bind(this, this.optionChanged_));
|
2013-04-06 22:30:12 +01:00
|
|
|
$(".game_hide_password", this.optionsElement_).click(cah.bind(this, this.showOrHidePassword_));
|
2012-01-25 08:03:41 +00:00
|
|
|
|
|
|
|
$(window).on("resize.game_" + this.id_, cah.bind(this, this.windowResize_));
|
2012-01-23 07:58:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load game data from the server and display the game lobby.
|
|
|
|
*
|
2012-01-31 07:53:00 +00:00
|
|
|
* TODO reload round win state
|
|
|
|
*
|
2012-02-20 20:34:26 +00:00
|
|
|
* @param {Number}
|
2012-01-23 07:58:36 +00:00
|
|
|
* gameId The game id.
|
|
|
|
*/
|
|
|
|
cah.Game.joinGame = function(gameId) {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.GET_GAME_INFO).withGameId(gameId).run();
|
2012-01-25 00:20:43 +00:00
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.GET_CARDS).withGameId(gameId).run();
|
2012-01-23 07:58:36 +00:00
|
|
|
cah.GameList.instance.hide();
|
2012-01-23 21:20:15 +00:00
|
|
|
var game = new cah.Game(gameId);
|
|
|
|
cah.currentGames[gameId] = game;
|
|
|
|
game.insertIntoDocument();
|
2013-11-11 03:22:54 +00:00
|
|
|
|
|
|
|
cah.updateHash('game=' + gameId);
|
2012-01-22 01:34:18 +00:00
|
|
|
};
|
|
|
|
|
2012-02-08 03:30:30 +00:00
|
|
|
/**
|
|
|
|
* Toggle showing the previous round result.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.showLastRoundClick_ = function() {
|
|
|
|
if (this.showingLastRound_) {
|
|
|
|
$(".game_show_last_round", this.element_).attr("value", "Show Last Round");
|
|
|
|
$(".game_black_card_round_indicator", this.element_).text("this round is");
|
|
|
|
$(".game_black_card", this.element_).empty().append(this.blackCard_.getElement());
|
|
|
|
$(".game_white_card_wrapper", this.element_).removeClass("hide");
|
|
|
|
$(".game_last_round", this.element_).addClass("hide");
|
|
|
|
} else {
|
|
|
|
$(".game_show_last_round", this.element_).attr("value", "Show Current Round");
|
|
|
|
$(".game_black_card_round_indicator", this.element_).text("last round was");
|
|
|
|
$(".game_black_card", this.element_).empty().append(this.lastBlackCard_.getElement());
|
|
|
|
$(".game_white_card_wrapper", this.element_).addClass("hide");
|
|
|
|
$(".game_last_round", this.element_).removeClass("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showingLastRound_ = !this.showingLastRound_;
|
|
|
|
};
|
|
|
|
|
2012-03-19 04:38:24 +00:00
|
|
|
/**
|
|
|
|
* Toggle showing the game's options.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.showOptionsClick_ = function() {
|
|
|
|
if (this.showingOptions_) {
|
|
|
|
this.showOptions_();
|
|
|
|
} else {
|
|
|
|
this.hideOptions_();
|
|
|
|
}
|
|
|
|
this.showingOptions_ = !this.showingOptions_;
|
|
|
|
};
|
|
|
|
|
2013-04-06 22:30:12 +01:00
|
|
|
/**
|
|
|
|
* Show or hide the game's password, based on the value of the checkbox.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.showOrHidePassword_ = function() {
|
|
|
|
if ($(".game_hide_password", this.optionsElement_).attr("checked")) {
|
|
|
|
$(".game_password", this.optionsElement_).hide();
|
|
|
|
$(".game_fake_password", this.optionsElement_).show();
|
|
|
|
$(".game_fake_password", this.optionsElement_).attr("value",
|
|
|
|
$(".game_password", this.optionsElement_).attr("value"));
|
|
|
|
$(".game_fake_password", this.optionsElement_).attr("disabled", "disabled");
|
|
|
|
} else {
|
|
|
|
$(".game_password", this.optionsElement_).show();
|
|
|
|
$(".game_fake_password", this.optionsElement_).hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-22 01:34:18 +00:00
|
|
|
/**
|
|
|
|
* @return {HTMLDivElement} This object's element.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.getElement = function() {
|
|
|
|
return this.element_;
|
|
|
|
};
|
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
/**
|
|
|
|
* Set the black card on display.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* card Black card data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.setBlackCard = function(card) {
|
|
|
|
this.blackCard_ = new cah.card.BlackCard(true, card[cah.$.BlackCardData.ID]);
|
|
|
|
this.blackCard_.setText(card[cah.$.BlackCardData.TEXT]);
|
2012-07-07 23:01:33 +01:00
|
|
|
this.blackCard_.setWatermark(card[cah.$.BlackCardData.WATERMARK]);
|
2012-02-01 04:22:07 +00:00
|
|
|
this.blackCard_.setDraw(card[cah.$.BlackCardData.DRAW]);
|
|
|
|
this.blackCard_.setPick(card[cah.$.BlackCardData.PICK]);
|
|
|
|
|
|
|
|
if (1 != card[cah.$.BlackCardData.PICK] && this.judge_ != cah.nickname) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "Play " + card[cah.$.BlackCardData.PICK]
|
2012-02-01 04:22:07 +00:00
|
|
|
+ " cards, in the order you wish them to be judged.");
|
|
|
|
}
|
2012-01-25 00:20:43 +00:00
|
|
|
|
2012-02-20 19:59:47 +00:00
|
|
|
if (!this.showingLastRound_) {
|
|
|
|
$(".game_black_card", this.element_).empty().append(this.blackCard_.getElement());
|
|
|
|
}
|
2012-01-25 00:20:43 +00:00
|
|
|
};
|
|
|
|
|
2012-01-23 23:06:20 +00:00
|
|
|
/**
|
|
|
|
* Add multiple cards to the player's hand.
|
|
|
|
*
|
|
|
|
* @param {Array}
|
|
|
|
* cards The array of card objects sent from the server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.dealtCards = function(cards) {
|
|
|
|
for ( var index in cards) {
|
|
|
|
var thisCard = cards[index];
|
|
|
|
var card = new cah.card.WhiteCard(true, thisCard[cah.$.WhiteCardData.ID]);
|
|
|
|
card.setText(thisCard[cah.$.WhiteCardData.TEXT]);
|
2012-07-07 23:01:33 +01:00
|
|
|
card.setWatermark(thisCard[cah.$.WhiteCardData.WATERMARK]);
|
2012-01-23 23:06:20 +00:00
|
|
|
this.dealtCard(card);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-23 07:58:36 +00:00
|
|
|
/**
|
|
|
|
* Add a card to the player's hand.
|
|
|
|
*
|
|
|
|
* @param {cah.card.WhiteCard}
|
|
|
|
* card Card to add to hand.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.dealtCard = function(card) {
|
|
|
|
this.hand_.push(card);
|
2012-01-24 01:41:02 +00:00
|
|
|
var element = card.getElement();
|
2012-01-25 06:39:19 +00:00
|
|
|
$(".game_hand_cards", this.element_).append(element);
|
2012-01-24 03:14:29 +00:00
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
$(element).css("transform-origin", "0 0");
|
2012-01-24 07:02:59 +00:00
|
|
|
|
2012-01-25 08:03:41 +00:00
|
|
|
var data = {
|
|
|
|
card : card,
|
|
|
|
};
|
2012-01-27 02:07:39 +00:00
|
|
|
$(element).on("mouseenter.hand", data, cah.bind(this, this.handCardMouseEnter_)).on(
|
|
|
|
"mouseleave.hand", data, cah.bind(this, this.handCardMouseLeave_)).on("click.hand", data,
|
2013-04-20 20:21:28 +01:00
|
|
|
cah.bind(this, this.handCardClick_)).on("keypress.hand", data,
|
|
|
|
cah.bind(this, this.handCardKeypress_));
|
2012-01-27 02:07:39 +00:00
|
|
|
|
|
|
|
this.resizeHandCards_();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a card from the hand.
|
|
|
|
*
|
|
|
|
* @param {cah.card.WhiteCard}
|
|
|
|
* card Card to remove.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.removeCardFromHand = function(card) {
|
|
|
|
var cardIndex = -1;
|
|
|
|
for ( var index in this.hand_) {
|
|
|
|
if (this.hand_[index] == card) {
|
|
|
|
cardIndex = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cardIndex != -1) {
|
|
|
|
$(card.getElement()).css("width", "").css("height", "").css("transform-origin", "").css(
|
|
|
|
"z-index", "").css("-moz-transform", "").css("-ms-transform", "").css("-webkit-transform",
|
|
|
|
"").css("-o-transform", "").off(".hand");
|
|
|
|
this.hand_.splice(cardIndex, 1);
|
|
|
|
}
|
2012-01-27 03:25:40 +00:00
|
|
|
|
|
|
|
$(card.getElement(), $("game_hand_cards", this.element_)).remove();
|
|
|
|
this.resizeHandCards_();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the round white cards.
|
|
|
|
*
|
|
|
|
* @param {Array}
|
2012-02-01 01:59:53 +00:00
|
|
|
* cardSets Array of arrays of cah.$.WhiteCardData to display.
|
2012-01-27 03:25:40 +00:00
|
|
|
*/
|
2012-02-01 01:59:53 +00:00
|
|
|
cah.Game.prototype.setRoundWhiteCards = function(cardSets) {
|
|
|
|
for ( var setIndex in cardSets) {
|
|
|
|
var thisSet = Array();
|
|
|
|
for ( var index in cardSets[setIndex]) {
|
|
|
|
var cardData = cardSets[setIndex][index];
|
|
|
|
var card;
|
|
|
|
var id = cardData[cah.$.WhiteCardData.ID];
|
|
|
|
if (id >= 0) {
|
|
|
|
card = new cah.card.WhiteCard(true, id);
|
|
|
|
card.setText(cardData[cah.$.WhiteCardData.TEXT]);
|
2012-07-07 23:01:33 +01:00
|
|
|
card.setWatermark(cardData[cah.$.WhiteCardData.WATERMARK]);
|
2012-02-01 01:59:53 +00:00
|
|
|
} else {
|
|
|
|
card = new cah.card.WhiteCard();
|
|
|
|
}
|
|
|
|
thisSet.push(card);
|
2012-01-27 03:25:40 +00:00
|
|
|
}
|
2012-02-01 01:59:53 +00:00
|
|
|
this.addRoundWhiteCard_(thisSet);
|
2012-01-27 03:25:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a white card to the round white cards area.
|
|
|
|
*
|
2012-02-01 01:59:53 +00:00
|
|
|
* @param {Array}
|
|
|
|
* cards Array of cah.card.WhiteCard to add to area.
|
2012-01-27 03:25:40 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2012-02-01 01:59:53 +00:00
|
|
|
cah.Game.prototype.addRoundWhiteCard_ = function(cards) {
|
|
|
|
var parentElem;
|
|
|
|
if (cards.length > 1) {
|
|
|
|
parentElem = $("#game_white_cards_binder_template").clone()[0];
|
|
|
|
parentElem.id = "";
|
|
|
|
$(parentElem).removeClass("hide");
|
|
|
|
$(".game_white_cards", this.element_).append(parentElem);
|
|
|
|
} else {
|
|
|
|
parentElem = $(".game_white_cards", this.element_)[0];
|
|
|
|
}
|
2012-01-27 08:14:48 +00:00
|
|
|
|
2012-02-01 01:59:53 +00:00
|
|
|
for ( var index in cards) {
|
|
|
|
var card = cards[index];
|
2012-01-27 08:14:48 +00:00
|
|
|
|
2012-02-01 01:59:53 +00:00
|
|
|
var element = card.getElement();
|
|
|
|
$(parentElem).append(element);
|
|
|
|
$(element).css("transform-origin", "0 0");
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
card : card,
|
|
|
|
};
|
|
|
|
$(element).on("mouseenter.round", data, cah.bind(this, this.roundCardMouseEnter_)).on(
|
|
|
|
"mouseleave.round", data, cah.bind(this, this.roundCardMouseLeave_)).on("click.round",
|
2013-04-20 20:21:28 +01:00
|
|
|
data, cah.bind(this, this.roundCardClick_)).on("keypress.round", data,
|
|
|
|
cah.bind(this, this.roundCardKeypress_));
|
2012-02-01 01:59:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
this.roundCards_[cards[0].getServerId()] = cards;
|
2012-01-27 23:41:57 +00:00
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
this.resizeRoundCards_();
|
2012-01-25 08:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for hand card mouse enter.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.handCardMouseEnter_ = function(e) {
|
2013-11-14 10:59:56 +00:00
|
|
|
if (!$(".game_animate_cards", this.element_).attr("checked")) return;
|
2012-01-27 08:14:48 +00:00
|
|
|
$(e.data.card.getElement()).css("z-index", "2").animate({
|
2012-01-25 08:03:41 +00:00
|
|
|
scale : this.handCardLargeScale_,
|
|
|
|
width : this.handCardLargeSize_,
|
|
|
|
}, {
|
2012-01-23 07:58:36 +00:00
|
|
|
duration : 200,
|
2012-01-24 01:41:02 +00:00
|
|
|
queue : false,
|
2012-01-25 08:03:41 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for hand card mouse leave.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.handCardMouseLeave_ = function(e) {
|
|
|
|
$(e.data.card.getElement()).animate({
|
|
|
|
scale : this.handCardSmallScale_,
|
|
|
|
"z-index" : 1,
|
|
|
|
width : this.handCardSmallSize_,
|
|
|
|
}, {
|
|
|
|
duration : 200,
|
|
|
|
queue : false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
/**
|
|
|
|
* Event handler for round card mouse enter.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.roundCardMouseEnter_ = function(e) {
|
2013-11-14 10:59:56 +00:00
|
|
|
if (!$(".game_animate_cards", this.element_).attr("checked")) return;
|
2012-03-17 01:34:20 +00:00
|
|
|
$(e.data.card.getElement()).css("z-index", "201").animate({
|
2012-01-27 08:14:48 +00:00
|
|
|
scale : this.roundCardLargeScale_,
|
|
|
|
width : this.roundCardLargeSize_,
|
|
|
|
}, {
|
|
|
|
duration : 200,
|
|
|
|
queue : false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for round card mouse leave.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.roundCardMouseLeave_ = function(e) {
|
|
|
|
$(e.data.card.getElement()).animate({
|
|
|
|
scale : this.roundCardSmallScale_,
|
2012-03-17 01:34:20 +00:00
|
|
|
"z-index" : 200,
|
2012-01-27 08:14:48 +00:00
|
|
|
width : this.roundCardSmallSize_,
|
|
|
|
}, {
|
|
|
|
duration : 200,
|
|
|
|
queue : false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-01-25 08:03:41 +00:00
|
|
|
/**
|
|
|
|
* Event handler for window resize.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.windowResize_ = function() {
|
|
|
|
this.resizeHandCards_();
|
2012-01-27 08:14:48 +00:00
|
|
|
this.resizeRoundCards_();
|
2012-01-25 08:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize cards in hand to fit window size and hand size.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.resizeHandCards_ = function() {
|
2012-02-08 01:06:23 +00:00
|
|
|
var data = {
|
|
|
|
class : ".game_hand_cards",
|
|
|
|
cardSmallSize : this.handCardSmallSize_,
|
|
|
|
cardLargeSize : this.handCardLargeSize_,
|
|
|
|
cardSmallScale : this.handCardSmallScale_,
|
|
|
|
cardLargeScale : this.handCardLargeScale_,
|
|
|
|
maxSmallSize : 150,
|
|
|
|
minSmallSize : 66,
|
|
|
|
smallSize : function() {
|
|
|
|
return ($(".game_hand_cards", this.element_).width() - 20)
|
|
|
|
/ ($(".game_hand_cards .card_holder", this.element_).length + 1);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
this.resizeCardHelper_(data);
|
|
|
|
this.handCardSmallSize_ = data.cardSmallSize;
|
|
|
|
this.handCardLargeSize_ = data.cardLargeSize;
|
|
|
|
this.handCardSmallScale_ = data.cardSmallScale;
|
|
|
|
this.handCardLargeScale_ = data.cardLargeScale;
|
2012-01-23 07:58:36 +00:00
|
|
|
};
|
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
/**
|
|
|
|
* Resize cards in the round white cards are to fit window size and number of players.
|
|
|
|
*
|
2012-02-06 22:00:24 +00:00
|
|
|
* TODO This will need some more consideration when there are multiple cards played per player,
|
|
|
|
* though it seems to mostly work.
|
2012-01-27 08:14:48 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.resizeRoundCards_ = function() {
|
|
|
|
$(".game_right_side", this.element_).width(
|
|
|
|
$(window).width() - $(".game_left_side", this.element_).width() - 30);
|
2012-02-08 01:06:23 +00:00
|
|
|
var data = {
|
|
|
|
class : ".game_white_cards",
|
|
|
|
cardSmallSize : this.roundCardSmallSize_,
|
|
|
|
cardLargeSize : this.roundCardLargeSize_,
|
|
|
|
cardSmallScale : this.roundCardSmallScale_,
|
|
|
|
cardLargeScale : this.roundCardLargeScale_,
|
|
|
|
maxSmallSize : 236,
|
|
|
|
minSmallSize : 118,
|
|
|
|
smallSize : function() {
|
|
|
|
return ($(window).width() - $(".game_left_side", this.element_).width() - 60)
|
|
|
|
/ $(".game_white_cards .card_holder", this.element_).length;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
this.resizeCardHelper_(data);
|
|
|
|
this.roundCardSmallSize_ = data.cardSmallSize;
|
|
|
|
this.roundCardLargeSize_ = data.cardLargeSize;
|
|
|
|
this.roundCardSmallScale_ = data.cardSmallScale;
|
|
|
|
this.roundCardLargeScale_ = data.cardLargeScale;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for resizing cards, so the logic only needs to be in one place.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* data In/out. Scale, size, and callback helper.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.resizeCardHelper_ = function(data) {
|
|
|
|
var elems = $(data.class + " .card_holder", this.element_);
|
|
|
|
|
|
|
|
data.cardSmallSize = data.smallSize();
|
|
|
|
if (data.cardSmallSize > data.maxSmallSize) {
|
|
|
|
data.cardSmallSize = data.maxSmallSize;
|
2012-01-27 08:14:48 +00:00
|
|
|
}
|
2012-02-08 01:06:23 +00:00
|
|
|
if (data.cardSmallSize < data.minSmallSize) {
|
|
|
|
data.cardSmallSize = data.minSmallSize;
|
2012-01-27 08:14:48 +00:00
|
|
|
}
|
2012-02-08 01:06:23 +00:00
|
|
|
var maxScale = 236 / data.cardSmallSize;
|
2012-01-27 08:14:48 +00:00
|
|
|
var scale = maxScale < 1.8 ? maxScale : 1.8;
|
2012-02-08 01:06:23 +00:00
|
|
|
data.cardLargeSize = data.cardSmallSize * scale;
|
|
|
|
if (data.cardLargeSize > 236) {
|
|
|
|
data.cardLargeSize = 236;
|
2012-01-27 08:14:48 +00:00
|
|
|
}
|
2012-02-08 01:06:23 +00:00
|
|
|
data.cardSmallScale = data.cardSmallSize / 236;
|
|
|
|
data.cardLargeScale = data.cardSmallScale * scale;
|
|
|
|
if (data.cardLargeScale > maxScale) {
|
|
|
|
data.cardLargeScale = maxScale;
|
2012-01-27 08:14:48 +00:00
|
|
|
}
|
2012-02-08 01:06:23 +00:00
|
|
|
elems.width(data.cardSmallSize).height(data.cardSmallSize).animate({
|
|
|
|
scale : data.cardSmallScale,
|
2012-01-27 08:14:48 +00:00
|
|
|
}, {
|
|
|
|
duration : 0,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Insert this game into the document.
|
|
|
|
*/
|
2012-01-23 07:58:36 +00:00
|
|
|
cah.Game.prototype.insertIntoDocument = function() {
|
|
|
|
$("#main_holder").empty().append(this.element_);
|
|
|
|
$("#info_area").empty().append(this.scoreboardElement_);
|
2012-01-23 21:20:15 +00:00
|
|
|
$("#leave_game").show();
|
2012-12-30 05:03:45 +00:00
|
|
|
|
|
|
|
var linkToChatArea = $("<a>");
|
2013-02-24 01:23:57 +00:00
|
|
|
this.gameChatTab_ = $("<li>");
|
2012-12-30 05:03:45 +00:00
|
|
|
linkToChatArea.attr("href", "#" + this.chatElement_.id);
|
|
|
|
linkToChatArea.text("Chat with game members");
|
2013-02-25 02:47:05 +00:00
|
|
|
linkToChatArea.addClass("tab-button");
|
2013-02-24 01:23:57 +00:00
|
|
|
this.gameChatTab_.append(linkToChatArea);
|
|
|
|
$("#tabs ul").append(this.gameChatTab_);
|
2012-12-30 05:03:45 +00:00
|
|
|
$("#tabs").append(this.chatElement_);
|
|
|
|
$("#tabs").tabs("refresh");
|
|
|
|
|
2013-02-25 02:47:05 +00:00
|
|
|
linkToChatArea.click();
|
2012-01-25 08:03:41 +00:00
|
|
|
this.windowResize_();
|
2012-01-23 07:58:36 +00:00
|
|
|
// TODO display a loading animation
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update game status display.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* data Game data returned from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.updateGameStatus = function(data) {
|
2012-07-07 23:01:33 +01:00
|
|
|
var gameInfo = data[cah.$.AjaxResponse.GAME_INFO];
|
|
|
|
this.host_ = gameInfo[cah.$.GameInfo.HOST];
|
2012-03-15 20:50:42 +00:00
|
|
|
|
2012-07-07 23:01:33 +01:00
|
|
|
if (this.host_ == cah.nickname && gameInfo[cah.$.GameInfo.STATE] == cah.$.GameState.LOBBY) {
|
2012-01-23 21:20:15 +00:00
|
|
|
$("#start_game").show();
|
2012-01-23 07:58:36 +00:00
|
|
|
} else {
|
2012-01-23 21:20:15 +00:00
|
|
|
$("#start_game").hide();
|
2012-01-22 01:34:18 +00:00
|
|
|
}
|
|
|
|
|
2012-07-07 23:01:33 +01:00
|
|
|
if (gameInfo[cah.$.GameInfo.STATE] == cah.$.GameState.LOBBY) {
|
2012-03-15 20:50:42 +00:00
|
|
|
this.showOptions_();
|
|
|
|
} else {
|
|
|
|
this.hideOptions_();
|
|
|
|
}
|
|
|
|
|
2012-07-07 23:01:33 +01:00
|
|
|
if (gameInfo[cah.$.GameInfo.STATE] == cah.$.GameState.PLAYING) {
|
2012-03-13 05:20:17 +00:00
|
|
|
// TODO this is the cause of the cards blanking when someone joins or leaves
|
2012-03-15 20:50:42 +00:00
|
|
|
// store the last state somewhere too?
|
2012-01-27 03:25:40 +00:00
|
|
|
$(".game_white_cards", this.element_).empty();
|
|
|
|
}
|
|
|
|
|
2012-07-07 23:01:33 +01:00
|
|
|
$(".score_limit", this.optionsElement_).val(gameInfo[cah.$.GameInfo.SCORE_LIMIT]);
|
|
|
|
$(".player_limit", this.optionsElement_).val(gameInfo[cah.$.GameInfo.PLAYER_LIMIT]);
|
2013-06-10 12:36:11 +01:00
|
|
|
$(".spectator_limit", this.optionsElement_).val(gameInfo[cah.$.GameInfo.SPECTATOR_LIMIT]);
|
2012-07-07 23:01:33 +01:00
|
|
|
$(".game_password", this.optionsElement_).val(gameInfo[cah.$.GameInfo.PASSWORD]);
|
2013-04-13 18:39:38 +01:00
|
|
|
if (gameInfo[cah.$.GameInfo.USE_TIMER]) {
|
|
|
|
$(".use_timer", this.optionsElement_).attr("checked", "checked");
|
|
|
|
} else {
|
|
|
|
$(".use_timer", this.optionsElement_).removeAttr("checked");
|
|
|
|
}
|
2012-07-07 23:01:33 +01:00
|
|
|
var cardSetIds = gameInfo[cah.$.GameInfo.CARD_SETS];// .split(',');
|
|
|
|
$(".card_set", this.optionsElement_).removeAttr("checked");
|
|
|
|
for ( var key in cardSetIds) {
|
|
|
|
var cardSetId = cardSetIds[key];
|
|
|
|
$("#card_set_" + this.id_ + "_" + cardSetId, this.optionsElement_).attr("checked", "checked");
|
|
|
|
}
|
2012-03-16 03:06:23 +00:00
|
|
|
|
2012-01-23 07:58:36 +00:00
|
|
|
var playerInfos = data[cah.$.AjaxResponse.PLAYER_INFO];
|
|
|
|
for ( var index in playerInfos) {
|
2012-01-27 02:07:39 +00:00
|
|
|
this.updateUserStatus(playerInfos[index]);
|
|
|
|
}
|
2013-06-10 12:36:11 +01:00
|
|
|
|
|
|
|
var spectators = gameInfo[cah.$.GameInfo.SPECTATORS];
|
|
|
|
for ( var index in spectators) {
|
|
|
|
this.updateSpectator(spectators[index]);
|
|
|
|
}
|
2012-01-27 02:07:39 +00:00
|
|
|
};
|
2012-01-25 00:20:43 +00:00
|
|
|
|
2012-01-27 02:07:39 +00:00
|
|
|
/**
|
|
|
|
* Update a single player's info.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* playerInfo The PlayerInfo from the server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.updateUserStatus = function(playerInfo) {
|
|
|
|
var playerName = playerInfo[cah.$.GamePlayerInfo.NAME];
|
|
|
|
var playerStatus = playerInfo[cah.$.GamePlayerInfo.STATUS];
|
|
|
|
var panel = this.scoreCards_[playerName];
|
|
|
|
if (!panel) {
|
|
|
|
// new score panel
|
|
|
|
panel = new cah.GameScorePanel(playerName);
|
2013-06-12 11:04:33 +01:00
|
|
|
if (this.firstSpectatorElement_) {
|
|
|
|
$(this.firstSpectatorElement_).before(panel.getElement());
|
|
|
|
} else {
|
|
|
|
$(this.scoreboardElement_).append(panel.getElement());
|
|
|
|
}
|
2012-01-27 02:07:39 +00:00
|
|
|
this.scoreCards_[playerName] = panel;
|
|
|
|
}
|
|
|
|
var oldStatus = panel.getStatus();
|
|
|
|
panel.update(playerInfo[cah.$.GamePlayerInfo.SCORE], playerStatus);
|
|
|
|
|
|
|
|
if (playerName == cah.nickname) {
|
|
|
|
$(".game_message", this.element_).text(cah.$.GamePlayerStatus_msg_2[playerStatus]);
|
2012-02-07 22:15:51 +00:00
|
|
|
|
2012-01-27 08:18:36 +00:00
|
|
|
if (playerStatus == cah.$.GamePlayerStatus.PLAYING && this.handSelectedCard_ != null) {
|
|
|
|
$(".confirm_card", this.element_).removeAttr("disabled");
|
|
|
|
} else if (playerStatus == cah.$.GamePlayerStatus.JUDGING && this.roundSelectedCard_ != null) {
|
2012-01-27 02:07:39 +00:00
|
|
|
$(".confirm_card", this.element_).removeAttr("disabled");
|
|
|
|
} else {
|
2012-01-27 06:17:36 +00:00
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
|
|
|
}
|
2012-02-07 22:15:51 +00:00
|
|
|
|
2012-01-27 06:17:36 +00:00
|
|
|
if (playerStatus != cah.$.GamePlayerStatus.PLAYING) {
|
2012-01-27 23:41:57 +00:00
|
|
|
if (this.handSelectedCard_ != null) {
|
|
|
|
// we have a card selected, but we're changing state. this almost certainly is an
|
|
|
|
// out-of-order reception of events. remove it from hand, we don't need to do anything else
|
|
|
|
this.removeCardFromHand(this.handSelectedCard_);
|
|
|
|
}
|
2012-01-27 02:07:39 +00:00
|
|
|
this.handSelectedCard_ = null;
|
|
|
|
$(".selected", $(".game_hand", this.element_)).removeClass("selected");
|
2012-01-25 00:20:43 +00:00
|
|
|
}
|
2012-02-07 22:15:51 +00:00
|
|
|
|
2012-01-31 00:35:06 +00:00
|
|
|
if (playerStatus == cah.$.GamePlayerStatus.HOST) {
|
|
|
|
$("#start_game").show();
|
|
|
|
}
|
2012-02-07 22:15:51 +00:00
|
|
|
|
|
|
|
if (playerStatus == cah.$.GamePlayerStatus.JUDGE) {
|
|
|
|
$(".game_hand_filter", this.element_).removeClass("hide");
|
|
|
|
$(".game_hand_filter_text", this.element_).text(cah.$.GamePlayerStatus_msg_2[playerStatus]);
|
|
|
|
} else if (playerStatus == cah.$.GamePlayerStatus.PLAYING) {
|
|
|
|
$(".game_hand_filter", this.element_).addClass("hide");
|
|
|
|
}
|
2012-01-27 02:07:39 +00:00
|
|
|
}
|
2012-01-25 06:39:19 +00:00
|
|
|
|
2012-01-27 02:07:39 +00:00
|
|
|
if (playerStatus == cah.$.GamePlayerStatus.JUDGE
|
|
|
|
|| playerStatus == cah.$.GamePlayerStatus.JUDGING) {
|
|
|
|
this.judge_ = playerName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldStatus == cah.$.GamePlayerStatus.PLAYING && playerStatus == cah.$.GamePlayerStatus.IDLE) {
|
2012-01-27 06:17:36 +00:00
|
|
|
// this player played a card. display a face-down white card in the area, or nothing if it is
|
|
|
|
// us. we put the card there when we get the acknowledgement from the server from playing.
|
2012-01-28 01:01:51 +00:00
|
|
|
// also, don't put the card up if we're already into judging state -- we already displayed all
|
|
|
|
// of the cards!
|
|
|
|
if (playerName != cah.nickname && this.state_ == cah.$.GameState.PLAYING) {
|
2012-02-01 22:26:20 +00:00
|
|
|
// TODO make this not suck for multiple selection. it only shows one card when they're done.
|
|
|
|
// TODO have some sort of way to know, from the server, how far along everybody is playing
|
|
|
|
// for multi-play
|
2012-02-01 01:59:53 +00:00
|
|
|
this.addRoundWhiteCard_(Array(new cah.card.WhiteCard()));
|
2012-01-25 06:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-10 12:36:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a single spectator's info.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* spectator The spectator name.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.updateSpectator = function(spectator) {
|
|
|
|
var panel = this.scoreCards_[spectator];
|
|
|
|
if (!panel) {
|
|
|
|
// new score panel
|
|
|
|
panel = new cah.GameScorePanel(spectator);
|
|
|
|
$(this.scoreboardElement_).append(panel.getElement());
|
|
|
|
this.scoreCards_[spectator] = panel;
|
2013-06-12 11:04:33 +01:00
|
|
|
if (!this.firstSpectatorElement_) {
|
|
|
|
this.firstSpectatorElement_ = panel.getElement();
|
|
|
|
}
|
2013-06-10 12:36:11 +01:00
|
|
|
}
|
|
|
|
panel.update(-1, cah.$.GamePlayerStatus.SPECTATOR);
|
|
|
|
|
|
|
|
if (spectator == cah.nickname) {
|
|
|
|
$(".game_message", this.element_).text(cah.$.GamePlayerStatus_msg_2[cah.$.GamePlayerStatus.SPECTATOR]);
|
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-27 23:41:57 +00:00
|
|
|
/**
|
|
|
|
* Round has completed. Update display of round cards to show winner.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* data Data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.roundComplete = function(data) {
|
2012-02-01 01:59:53 +00:00
|
|
|
var cards = this.roundCards_[data[cah.$.LongPollResponse.WINNING_CARD]];
|
2013-04-20 20:21:28 +01:00
|
|
|
var ariaText = '';
|
2012-02-01 01:59:53 +00:00
|
|
|
for ( var index in cards) {
|
|
|
|
var card = cards[index];
|
|
|
|
$(".card", card.getElement()).addClass("selected");
|
2013-04-20 20:21:28 +01:00
|
|
|
ariaText += card.getAriaText();
|
2012-02-01 01:59:53 +00:00
|
|
|
}
|
2012-02-08 03:30:30 +00:00
|
|
|
var roundWinner = data[cah.$.LongPollResponse.ROUND_WINNER];
|
|
|
|
var scoreCard = this.scoreCards_[roundWinner];
|
2012-01-27 23:41:57 +00:00
|
|
|
$(scoreCard.getElement()).addClass("selected");
|
2012-01-30 08:35:56 +00:00
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
2013-11-14 10:39:03 +00:00
|
|
|
cah.log.status_with_game(this, roundWinner + " wins the round. The next round will begin in "
|
2012-01-27 23:41:57 +00:00
|
|
|
+ (data[cah.$.LongPollResponse.INTERMISSION] / 1000) + " seconds.");
|
2012-02-08 03:30:30 +00:00
|
|
|
|
|
|
|
// update the previous round display
|
|
|
|
$(".game_last_round_winner", this.element_).text(roundWinner);
|
|
|
|
$(".game_last_round_cards", this.element_).empty().append(
|
|
|
|
$(".game_white_card_wrapper .card_holder", this.element_).clone());
|
|
|
|
this.lastBlackCard_ = this.blackCard_;
|
|
|
|
$(".game_show_last_round", this.element_).removeAttr("disabled");
|
2013-04-20 20:21:28 +01:00
|
|
|
|
|
|
|
// speak it in screen readers
|
|
|
|
cah.log.ariaStatus("The round was won by " + roundWinner + " with " + ariaText);
|
2012-01-27 23:41:57 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 23:59:50 +00:00
|
|
|
/**
|
|
|
|
* Notify the user that they are running out of time to play.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.hurryUp = function() {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this,
|
|
|
|
"Hurry up! You have less than 10 seconds to decide, or you will be skipped.");
|
2012-03-16 23:59:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A player was kicked due to being idle.
|
|
|
|
*
|
|
|
|
* @param {object}
|
|
|
|
* data Event data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.playerKickedIdle = function(data) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, data[cah.$.LongPollResponse.NICKNAME]
|
2012-03-16 23:59:50 +00:00
|
|
|
+ " was kicked for being idle for too many rounds.");
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A player was skipped due to being idle.
|
|
|
|
*
|
|
|
|
* @param {obejct}
|
|
|
|
* data Event data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.playerSkipped = function(data) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, data[cah.$.LongPollResponse.NICKNAME]
|
2012-03-16 23:59:50 +00:00
|
|
|
+ " was skipped this round for being idle for too long.");
|
|
|
|
};
|
|
|
|
|
2012-01-31 00:35:06 +00:00
|
|
|
/**
|
|
|
|
* Notify the player that a deck has been reshuffled.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* deck Deck name which has been reshuffled.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.reshuffle = function(deck) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "The " + deck + " deck has been reshuffled.");
|
2012-01-31 00:35:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the player that the judge has left the game and cards are being returned to hands.
|
2012-03-16 06:43:43 +00:00
|
|
|
*
|
|
|
|
* @param {object}
|
|
|
|
* data Event data from the server.
|
2012-01-31 00:35:06 +00:00
|
|
|
*/
|
2012-03-16 06:43:43 +00:00
|
|
|
cah.Game.prototype.judgeLeft = function(data) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this,
|
|
|
|
"The Card Czar has left the game. Cards played this round are being returned to hands.");
|
|
|
|
cah.log.status_with_game(this, "The next round will begin in "
|
2012-03-16 06:43:43 +00:00
|
|
|
+ (data[cah.$.LongPollResponse.INTERMISSION] / 1000) + " seconds.");
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "(Displayed state will look weird until the next round.)");
|
2012-01-31 00:35:06 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 23:59:50 +00:00
|
|
|
/**
|
|
|
|
* The judge was skipped for taking too long.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.judgeSkipped = function() {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "The Card Czar has taken too long to decide and has been skipped."
|
|
|
|
+ " Cards played this round are being returned to hands.");
|
2012-03-16 23:59:50 +00:00
|
|
|
};
|
|
|
|
|
2012-01-25 06:39:19 +00:00
|
|
|
/**
|
|
|
|
* Event handler for confirm selection button.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.confirmClick_ = function() {
|
2012-01-27 02:07:39 +00:00
|
|
|
if (this.judge_ == cah.nickname) {
|
2012-01-27 23:41:57 +00:00
|
|
|
if (this.roundSelectedCard_ != null) {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.JUDGE_SELECT).withGameId(this.id_).withCardId(
|
|
|
|
this.roundSelectedCard_.getServerId()).run();
|
|
|
|
}
|
2012-01-27 02:07:39 +00:00
|
|
|
} else {
|
|
|
|
if (this.handSelectedCard_ != null) {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.PLAY_CARD).withGameId(this.id_).withCardId(
|
|
|
|
this.handSelectedCard_.getServerId()).run();
|
|
|
|
}
|
|
|
|
}
|
2012-01-25 06:39:19 +00:00
|
|
|
};
|
|
|
|
|
2013-04-20 20:21:28 +01:00
|
|
|
/**
|
|
|
|
* Event handler for pressing a key on a card in the hand.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.handCardKeypress_ = function(e) {
|
|
|
|
if (32 == e.which) {
|
|
|
|
this.handCardClick_(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-25 06:39:19 +00:00
|
|
|
/**
|
|
|
|
* Event handler for clicking on a card in the hand.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.handCardClick_ = function(e) {
|
|
|
|
// judge can't select a card.
|
|
|
|
if (this.judge_ == cah.nickname) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-27 03:25:40 +00:00
|
|
|
// this player isn't in playing state
|
|
|
|
var scorecard = this.scoreCards_[cah.nickname];
|
|
|
|
if (scorecard && scorecard.getStatus() != cah.$.GamePlayerStatus.PLAYING) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-25 06:39:19 +00:00
|
|
|
/** @type {cah.card.WhiteCard} */
|
|
|
|
var card = e.data.card;
|
|
|
|
|
|
|
|
// remove style from existing selected card
|
|
|
|
if (this.handSelectedCard_) {
|
|
|
|
$(".card", this.handSelectedCard_.getElement()).removeClass("selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the user clicked on the same card, deselect it.
|
|
|
|
if (card == this.handSelectedCard_) {
|
|
|
|
this.handSelectedCard_ = null;
|
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
2013-04-20 20:21:28 +01:00
|
|
|
cah.log.ariaStatus("Deselected card.");
|
2012-01-25 06:39:19 +00:00
|
|
|
} else {
|
|
|
|
this.handSelectedCard_ = card;
|
|
|
|
$(".card", card.getElement()).addClass("selected");
|
|
|
|
$(".confirm_card", this.element_).removeAttr("disabled");
|
2013-04-20 20:21:28 +01:00
|
|
|
cah.log.ariaStatus("Selected card.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for pressing a key on a card in the round.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.roundCardKeypress_ = function(e) {
|
|
|
|
if (32 == e.which) {
|
|
|
|
this.roundCardClick_(e);
|
2012-01-23 07:58:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-27 08:14:48 +00:00
|
|
|
/**
|
|
|
|
* Event handler for clicking on a card in the round.
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.roundCardClick_ = function(e) {
|
|
|
|
// this player isn't in judging state.
|
|
|
|
var scorecard = this.scoreCards_[cah.nickname];
|
|
|
|
if (scorecard && scorecard.getStatus() != cah.$.GamePlayerStatus.JUDGING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/** @type {cah.card.WhiteCard} */
|
|
|
|
var card = e.data.card;
|
|
|
|
|
|
|
|
// remove style from existing selected card
|
|
|
|
if (this.roundSelectedCard_) {
|
|
|
|
$(".card", this.roundSelectedCard_.getElement()).removeClass("selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the user clicked on the same card, deselect it.
|
|
|
|
if (card == this.roundSelectedCard_) {
|
|
|
|
this.roundSelectedCard_ = null;
|
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
2013-04-20 20:21:28 +01:00
|
|
|
cah.log.ariaStatus("Deselected card.");
|
2012-01-27 08:14:48 +00:00
|
|
|
} else {
|
|
|
|
this.roundSelectedCard_ = card;
|
|
|
|
$(".card", card.getElement()).addClass("selected");
|
|
|
|
$(".confirm_card", this.element_).removeAttr("disabled");
|
2013-04-20 20:21:28 +01:00
|
|
|
cah.log.ariaStatus("Selected card.");
|
2012-01-27 08:14:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-23 21:20:15 +00:00
|
|
|
/**
|
|
|
|
* Event handler for leave game button.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.leaveGameClick_ = function() {
|
2012-01-23 23:06:20 +00:00
|
|
|
// TODO make sure everything cleans up right, I got an error when I tried to start a different
|
|
|
|
// game after leaving one
|
2012-03-15 20:50:42 +00:00
|
|
|
if (confirm("Are you sure you wish to leave the game?")) {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.LEAVE_GAME).withGameId(this.id_).run();
|
2013-02-24 01:23:57 +00:00
|
|
|
$(this.chatElement_).detach();
|
|
|
|
$(this.gameChatTab_).detach();
|
|
|
|
$("#tabs").tabs("refresh");
|
2012-03-15 20:50:42 +00:00
|
|
|
}
|
2012-01-23 21:20:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for start game button.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.startGameClick_ = function() {
|
2012-01-25 00:20:43 +00:00
|
|
|
// TODO make the button go disabled
|
2012-01-23 23:06:20 +00:00
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.START_GAME).withGameId(this.id_).run();
|
2012-01-23 21:20:15 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Called when the call to the server to start the game has completed successfully.
|
|
|
|
*/
|
2012-01-25 00:20:43 +00:00
|
|
|
cah.Game.prototype.startGameComplete = function() {
|
|
|
|
$("#start_game").hide();
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Called when the call to the server to play a card has completed successfully.
|
|
|
|
*/
|
2012-01-27 02:07:39 +00:00
|
|
|
cah.Game.prototype.playCardComplete = function() {
|
|
|
|
if (this.handSelectedCard_) {
|
|
|
|
$(".card", this.handSelectedCard_.getElement()).removeClass("selected");
|
2012-02-01 22:26:20 +00:00
|
|
|
// TODO support for multiple play, though it seems to be working now...
|
2012-01-27 02:07:39 +00:00
|
|
|
this.removeCardFromHand(this.handSelectedCard_);
|
2012-02-01 01:59:53 +00:00
|
|
|
this.addRoundWhiteCard_(Array(this.handSelectedCard_));
|
2012-01-27 02:07:39 +00:00
|
|
|
this.handSelectedCard_ = null;
|
|
|
|
}
|
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
|
|
|
};
|
|
|
|
|
2012-01-23 21:20:15 +00:00
|
|
|
/**
|
|
|
|
* Free resources used by this game and remove from the document.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.dispose = function() {
|
|
|
|
$(this.element_).remove();
|
|
|
|
$(this.scoreboardElement_).remove();
|
2012-01-24 01:41:02 +00:00
|
|
|
$("#leave_game").unbind().hide();
|
|
|
|
$("#start_game").unbind().hide();
|
2012-01-25 08:03:41 +00:00
|
|
|
$(window).off("resize.game_" + this.id_);
|
2013-11-11 03:22:54 +00:00
|
|
|
|
|
|
|
cah.updateHash('');
|
2012-01-23 21:20:15 +00:00
|
|
|
};
|
|
|
|
|
2012-01-23 21:37:11 +00:00
|
|
|
/**
|
|
|
|
* A player has joined the game.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* player Player that joined.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.playerJoin = function(player) {
|
|
|
|
if (player != cah.nickname) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, player + " has joined the game.");
|
2012-01-23 21:37:11 +00:00
|
|
|
this.refreshGameStatus();
|
|
|
|
} else {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "You have joined the game.");
|
2012-01-23 21:37:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A player has left the game.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* player Player that left.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.playerLeave = function(player) {
|
|
|
|
if (player != cah.nickname) {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, player + " has left the game.");
|
2012-01-23 21:37:11 +00:00
|
|
|
this.refreshGameStatus();
|
|
|
|
} else {
|
2013-02-25 02:57:04 +00:00
|
|
|
cah.log.status_with_game(this, "You have left the game.");
|
2012-01-23 21:37:11 +00:00
|
|
|
}
|
|
|
|
var scorecard = this.scoreCards_[player];
|
|
|
|
if (scorecard) {
|
|
|
|
$(scorecard.getElement()).remove();
|
|
|
|
}
|
|
|
|
delete this.scoreCards_[player];
|
|
|
|
};
|
|
|
|
|
2013-06-10 12:36:11 +01:00
|
|
|
/**
|
|
|
|
* A spectator has joined the game.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* spectator Spectator that joined.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.spectatorJoin = function(spectator) {
|
|
|
|
if (spectator != cah.nickname) {
|
|
|
|
cah.log.status_with_game(this, spectator + " has started spectating the game.");
|
|
|
|
this.refreshGameStatus();
|
|
|
|
} else {
|
|
|
|
cah.log.status_with_game(this, "You have started spectating the game.");
|
|
|
|
}
|
|
|
|
this.updateSpectator(spectator);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A spectator has left the game.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* spectator Spectator that left.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.spectatorLeave = function(spectator) {
|
|
|
|
if (spectator != cah.nickname) {
|
|
|
|
cah.log.status_with_game(this, spectator + " has stopped spectating the game.");
|
|
|
|
this.refreshGameStatus();
|
|
|
|
} else {
|
|
|
|
cah.log.status_with_game(this, "You have stopped spectating the game.");
|
|
|
|
}
|
|
|
|
var scorecard = this.scoreCards_[spectator];
|
|
|
|
if (scorecard) {
|
2013-06-12 11:04:33 +01:00
|
|
|
if (this.firstSpectatorElement_ == scorecard.getElement()) {
|
|
|
|
this.firstSpectatorElement_ = this.firstSpectatorElement_.nextSibling;
|
|
|
|
}
|
2013-06-10 12:36:11 +01:00
|
|
|
$(scorecard.getElement()).remove();
|
|
|
|
}
|
|
|
|
delete this.scoreCards_[spectator];
|
|
|
|
};
|
|
|
|
|
2012-01-23 21:37:11 +00:00
|
|
|
/**
|
|
|
|
* Refresh game scoreboard, etc.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.refreshGameStatus = function() {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.GET_GAME_INFO).withGameId(this.id_).run();
|
|
|
|
};
|
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
/**
|
|
|
|
* The game state has changed.
|
|
|
|
*
|
|
|
|
* @param {Object}
|
|
|
|
* data Data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.stateChange = function(data) {
|
|
|
|
this.state_ = data[cah.$.LongPollResponse.GAME_STATE];
|
|
|
|
|
2012-01-27 23:41:57 +00:00
|
|
|
$(".scorecard", this.scoreboardElement_).removeClass("selected");
|
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
switch (this.state_) {
|
|
|
|
case cah.$.GameState.LOBBY:
|
2012-01-27 06:17:36 +00:00
|
|
|
var handCount = this.hand_.length;
|
|
|
|
for ( var i = 0; i < handCount; i++) {
|
|
|
|
this.removeCardFromHand(this.hand_[0]);
|
|
|
|
}
|
|
|
|
this.handSelectedCard_ = null;
|
|
|
|
this.judge_ = null;
|
|
|
|
$(".confirm_card", this.element_).attr("disabled", "disabled");
|
|
|
|
$(".game_black_card", this.element_).empty();
|
2012-01-27 23:41:57 +00:00
|
|
|
for ( var index in this.roundCards_) {
|
|
|
|
$(this.roundCards_[index]).off(".round");
|
|
|
|
}
|
|
|
|
this.roundCards_ = {};
|
2012-01-27 06:17:36 +00:00
|
|
|
$(".game_white_cards", this.element_).empty();
|
2013-11-14 10:46:29 +00:00
|
|
|
$(".game_hand_filter", this.element_).addClass("hide"); // in case they were the judge last round
|
2012-03-15 20:50:42 +00:00
|
|
|
|
|
|
|
this.showOptions_();
|
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
break;
|
2012-01-27 06:17:36 +00:00
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
case cah.$.GameState.PLAYING:
|
2012-03-15 20:50:42 +00:00
|
|
|
this.hideOptions_();
|
2012-01-25 00:20:43 +00:00
|
|
|
this.refreshGameStatus();
|
|
|
|
this.setBlackCard(data[cah.$.LongPollResponse.BLACK_CARD]);
|
|
|
|
break;
|
2012-01-27 06:17:36 +00:00
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
case cah.$.GameState.JUDGING:
|
2012-01-27 06:17:36 +00:00
|
|
|
$(".game_white_cards", this.element_).empty();
|
|
|
|
this.setRoundWhiteCards(data[cah.$.LongPollResponse.WHITE_CARDS]);
|
2012-01-25 00:20:43 +00:00
|
|
|
break;
|
2012-01-27 06:17:36 +00:00
|
|
|
|
2012-01-25 00:20:43 +00:00
|
|
|
default:
|
|
|
|
cah.log.error("Game " + this.id_ + " changed to unknown state " + this.state_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-16 03:06:23 +00:00
|
|
|
/**
|
|
|
|
* Hide the options panel.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.hideOptions_ = function() {
|
2012-03-19 04:38:24 +00:00
|
|
|
$(".game_show_options", this.element_).val("Show Game Options");
|
2012-03-16 03:06:23 +00:00
|
|
|
$(".game_options", this.element_).addClass("hide");
|
|
|
|
$(".game_right_side", this.element_).removeClass("hide");
|
|
|
|
};
|
|
|
|
|
2012-03-15 20:50:42 +00:00
|
|
|
/**
|
|
|
|
* Show the options panel. Enables or disables the controls based on whether we are the host.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.showOptions_ = function() {
|
2012-03-19 04:38:24 +00:00
|
|
|
$(".game_show_options", this.element_).val("Hide Game Options");
|
2012-03-16 03:06:23 +00:00
|
|
|
$(".game_options", this.element_).removeClass("hide");
|
|
|
|
$(".game_right_side", this.element_).addClass("hide");
|
2012-03-15 20:50:42 +00:00
|
|
|
this.updateOptionsEnabled_();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable or disable the option controls depending on whether we are the host.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.updateOptionsEnabled_ = function() {
|
2012-03-19 04:38:24 +00:00
|
|
|
if (this.host_ == cah.nickname && this.state_ == cah.$.GameState.LOBBY) {
|
2012-03-15 20:50:42 +00:00
|
|
|
$("select", this.optionsElement_).removeAttr("disabled");
|
2012-03-19 04:20:48 +00:00
|
|
|
$("input", this.optionsElement_).removeAttr("disabled");
|
2012-03-16 03:06:23 +00:00
|
|
|
$(".options_host_only", this.optionsElement_).addClass("hide");
|
2012-03-15 20:50:42 +00:00
|
|
|
} else {
|
|
|
|
$("select", this.optionsElement_).attr("disabled", "disabled");
|
2012-03-19 04:20:48 +00:00
|
|
|
$("input", this.optionsElement_).attr("disabled", "disabled");
|
2012-03-16 03:06:23 +00:00
|
|
|
$(".options_host_only", this.optionsElement_).removeClass("hide");
|
2012-03-15 20:50:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-03-16 03:06:23 +00:00
|
|
|
* Event handler for changing an option.
|
2012-03-15 20:50:42 +00:00
|
|
|
*
|
2012-03-16 03:06:23 +00:00
|
|
|
* @param e
|
2012-03-15 20:50:42 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2012-03-16 03:06:23 +00:00
|
|
|
cah.Game.prototype.optionChanged_ = function(e) {
|
2012-07-07 23:01:33 +01:00
|
|
|
var selectedCardSets = $(".card_sets :checked", this.optionsElement_);
|
|
|
|
var cardSetIds = [];
|
|
|
|
for ( var i = 0; i < selectedCardSets.length; i++) {
|
|
|
|
cardSetIds.push(selectedCardSets[i].value);
|
|
|
|
}
|
2012-03-16 03:06:23 +00:00
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.CHANGE_GAME_OPTIONS).withGameId(this.id_).withScoreLimit(
|
|
|
|
$(".score_limit", this.optionsElement_).val()).withPlayerLimit(
|
2013-06-10 12:36:11 +01:00
|
|
|
$(".player_limit", this.optionsElement_).val()).withSpectatorLimit(
|
|
|
|
$(".spectator_limit", this.optionsElement_).val()).withCardSets(cardSetIds).withPassword(
|
2013-04-13 18:39:38 +01:00
|
|
|
$(".game_password", this.optionsElement_).val()).withUseTimer(
|
|
|
|
!!$('.use_timer', this.optionsElement_).attr('checked')).run();
|
2012-03-16 03:06:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {object}
|
|
|
|
* data Event data from server.
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.optionsChanged = function(data) {
|
2012-03-19 04:20:48 +00:00
|
|
|
this.updateGameStatus(data);
|
2012-03-15 20:50:42 +00:00
|
|
|
};
|
|
|
|
|
2013-02-25 02:57:04 +00:00
|
|
|
/**
|
|
|
|
* @returns This game's chat element.
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
*/
|
|
|
|
cah.Game.prototype.getChatElement = function() {
|
|
|
|
return this.chatElement_;
|
|
|
|
};
|
|
|
|
|
2012-01-23 07:58:36 +00:00
|
|
|
// ///////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a scoreboard panel for a player.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* player Player name.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
cah.GameScorePanel = function(player) {
|
|
|
|
/**
|
|
|
|
* Player name.
|
|
|
|
*
|
|
|
|
* @type {String}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.player_ = player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {HTMLDivElement}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.element_ = $("#scorecard_template").clone()[0];
|
2012-02-06 22:00:24 +00:00
|
|
|
this.element_.id = "";
|
2012-01-23 07:58:36 +00:00
|
|
|
$(this.element_).removeClass("hide");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The score on this scorecard.
|
|
|
|
*
|
2012-02-20 20:34:26 +00:00
|
|
|
* @type {Number}
|
2012-01-23 07:58:36 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.score_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The status of the player for this scorecard.
|
|
|
|
*
|
|
|
|
* @type {cah.$.GamePlayerStatus}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.status_ = cah.$.GamePlayerStatus.IDLE;
|
|
|
|
|
2013-04-20 20:21:28 +01:00
|
|
|
$(".scorecard_player", this.element_).text(player);
|
2012-01-23 07:58:36 +00:00
|
|
|
this.update(this.score_, this.status_);
|
|
|
|
};
|
|
|
|
|
|
|
|
cah.GameScorePanel.prototype.getElement = function() {
|
|
|
|
return this.element_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the score panel.
|
|
|
|
*
|
|
|
|
* TODO add some color for different statuses
|
|
|
|
*
|
2012-02-20 20:34:26 +00:00
|
|
|
* @param {Number}
|
2012-01-23 07:58:36 +00:00
|
|
|
* score The player's score
|
|
|
|
* @param {cah.$.GamePlayerStatus}
|
|
|
|
* status The player's status.
|
|
|
|
*/
|
|
|
|
cah.GameScorePanel.prototype.update = function(score, status) {
|
|
|
|
this.score_ = score;
|
|
|
|
this.status_ = status;
|
2012-01-30 08:35:56 +00:00
|
|
|
$(".scorecard_score", this.element_).text(score);
|
|
|
|
$(".scorecard_status", this.element_).text(cah.$.GamePlayerStatus_msg[status]);
|
|
|
|
$(".scorecard_s", this.element_).text(score == 1 ? "" : "s");
|
2013-06-10 12:36:11 +01:00
|
|
|
if (score < 0) {
|
|
|
|
$(".scorecard_points", this.element_).addClass("hide");
|
|
|
|
$(this.element_).attr("aria-label", this.player_ + ". "
|
|
|
|
+ cah.$.GamePlayerStatus_msg[status]);
|
|
|
|
} else {
|
|
|
|
$(".scorecard_points", this.element_).removeClass("hide");
|
2013-06-12 11:04:33 +01:00
|
|
|
$(this.element_).attr(
|
|
|
|
"aria-label",
|
|
|
|
this.player_ + " has " + score + " Awesome Point" + (score == 1 ? "" : "s") + ". "
|
|
|
|
+ cah.$.GamePlayerStatus_msg[status]);
|
2013-06-10 12:36:11 +01:00
|
|
|
}
|
2012-01-23 07:58:36 +00:00
|
|
|
};
|
2012-01-24 01:41:02 +00:00
|
|
|
|
2012-01-27 02:07:39 +00:00
|
|
|
/**
|
|
|
|
* @returns {cah.$.GamePlayerStatus} The status of the player represented by this panel.
|
|
|
|
*/
|
|
|
|
cah.GameScorePanel.prototype.getStatus = function() {
|
|
|
|
return this.status_;
|
|
|
|
};
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/*
|
2012-01-29 07:33:21 +00:00
|
|
|
* confirm card as judge without selecting a round card did ... something
|
|
|
|
*
|
|
|
|
* don't always see your card after playing it
|
2012-01-28 01:01:51 +00:00
|
|
|
*/
|