todo cleanup for multi-play

This commit is contained in:
Andy Janata 2012-02-01 14:26:20 -08:00
parent b5cb45353c
commit 582537b0a1
2 changed files with 31 additions and 44 deletions

View File

@ -102,6 +102,8 @@ cah.Game = function(id) {
*
* TODO make this an array when we support the multiple play blacks
*
* TODO what, exactly, is this being used for, since multi-play seems to be working...
*
* @type {cah.card.WhiteCard}
* @private
*/
@ -249,8 +251,6 @@ cah.Game.prototype.dealtCards = function(cards) {
/**
* Add a card to the player's hand.
*
* TODO: in IE, for some reason, the logo is only on the leftmost card.
*
* @param {cah.card.WhiteCard}
* card Card to add to hand.
*/
@ -582,7 +582,9 @@ cah.Game.prototype.updateUserStatus = function(playerInfo) {
// 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) {
// TODO make this not suck for multiple selection
// 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
this.addRoundWhiteCard_(Array(new cah.card.WhiteCard()));
}
}
@ -633,7 +635,6 @@ cah.Game.prototype.judgeLeft = function() {
cah.Game.prototype.confirmClick_ = function() {
if (this.judge_ == cah.nickname) {
if (this.roundSelectedCard_ != null) {
// TODO fix for multiple select
cah.Ajax.build(cah.$.AjaxOperation.JUDGE_SELECT).withGameId(this.id_).withCardId(
this.roundSelectedCard_.getServerId()).run();
}
@ -739,7 +740,7 @@ cah.Game.prototype.startGameComplete = function() {
cah.Game.prototype.playCardComplete = function() {
if (this.handSelectedCard_) {
$(".card", this.handSelectedCard_.getElement()).removeClass("selected");
// TODO support for multiple play
// TODO support for multiple play, though it seems to be working now...
this.myPlayedCard_ = this.handSelectedCard_;
this.removeCardFromHand(this.handSelectedCard_);
this.addRoundWhiteCard_(Array(this.handSelectedCard_));

View File

@ -53,7 +53,6 @@ public class Game {
private final int id;
private final List<Player> players = new ArrayList<Player>(10);
private final List<Player> roundPlayers = new ArrayList<Player>(9);
// TODO make this Map<Player, List<WhiteCard>> once we support the multiple play black cards
private final PlayerPlayedCardsTracker playedCards = new PlayerPlayedCardsTracker();
private final ConnectedUsers connectedUsers;
private final GameManager gameManager;
@ -138,7 +137,6 @@ public class Game {
synchronized (playedCards) {
if (playedCards.hasPlayer(player)) {
synchronized (whiteDeck) {
// FIXME for multi-play
final List<WhiteCard> cards = playedCards.getCards(player);
for (final WhiteCard card : cards) {
whiteDeck.discard(card);
@ -151,8 +149,7 @@ public class Game {
synchronized (roundPlayers) {
if (roundPlayers.contains(player)) {
roundPlayers.remove(player);
if (roundPlayers.size() == playedCards.size()) {
// FIXME for multi-play
if (startJudging()) {
judgingState();
}
}
@ -172,7 +169,6 @@ public class Game {
data.put(LongPollResponse.EVENT, LongPollEvent.GAME_JUDGE_LEFT.toString());
broadcastToPlayers(MessageType.GAME_EVENT, data);
synchronized (playedCards) {
// FIXME for multi-play
for (final Player p : playedCards.playedPlayers()) {
p.getHand().addAll(playedCards.getCards(p));
sendCardsToPlayer(p, playedCards.getCards(p));
@ -586,7 +582,6 @@ public class Game {
if (state != GameState.JUDGING) {
return new ArrayList<List<Map<WhiteCardData, Object>>>();
} else {
// TODO fix this for multi-play
final List<List<WhiteCard>> shuffledPlayedCards;
synchronized (playedCards) {
shuffledPlayedCards = new ArrayList<List<WhiteCard>>(playedCards.cards());
@ -595,9 +590,6 @@ public class Game {
final List<List<Map<WhiteCardData, Object>>> cardData =
new ArrayList<List<Map<WhiteCardData, Object>>>(shuffledPlayedCards.size());
Collections.shuffle(shuffledPlayedCards);
// for (final WhiteCard card : shuffledPlayedCards) {
// cardData.add(card.getClientData());
// }
for (final List<WhiteCard> cards : shuffledPlayedCards) {
cardData.add(getWhiteCardData(cards));
}
@ -619,7 +611,6 @@ public class Game {
} else if (state != GameState.PLAYING) {
return new ArrayList<List<Map<WhiteCardData, Object>>>();
} else {
// TODO fix this for multi-play
synchronized (playedCards) {
final List<List<Map<WhiteCardData, Object>>> cardData =
new ArrayList<List<Map<WhiteCardData, Object>>>(playedCards.size());
@ -629,7 +620,7 @@ public class Game {
cardData.add(getWhiteCardData(playedCards.getCards(player)));
blankCards--;
}
// TODO make this figure out how many blank cards in each spot
// TODO make this figure out how many blank cards in each spot, for multi-play cards
while (blankCards-- > 0) {
cardData.add(Arrays.asList(WhiteCard.getBlankCardClientData()));
}
@ -700,21 +691,10 @@ public class Game {
data.put(LongPollResponse.PLAYER_INFO, getPlayerInfo(player));
broadcastToPlayers(MessageType.GAME_PLAYER_EVENT, data);
// TODO make this check that everybody has played proper number of cards when we support
// multiple play blacks
if (playedCards.size() == roundPlayers.size()) {
boolean startJudging = true;
for (final List<WhiteCard> cards : playedCards.cards()) {
if (cards.size() != blackCard.getPick()) {
startJudging = false;
break;
}
}
if (startJudging) {
if (startJudging()) {
judgingState();
}
}
}
return null;
} else {
return ErrorCode.DO_NOT_HAVE_CARD;
@ -724,6 +704,27 @@ public class Game {
}
}
/**
* Check to see if judging should begin, based on the number of players that have played and the
* number of cards they have played.
*
* @return True if judging should begin.
*/
private boolean startJudging() {
if (playedCards.size() == roundPlayers.size()) {
boolean startJudging = true;
for (final List<WhiteCard> cards : playedCards.cards()) {
if (cards.size() != blackCard.getPick()) {
startJudging = false;
break;
}
}
return startJudging;
} else {
return false;
}
}
/**
* The judge has selected a card. The {@code cardId} passed in may be any white cards's ID for
* black cards that have multiple selection, however only the first card in the set's ID will be
@ -801,7 +802,6 @@ public class Game {
synchronized (whiteDeck) {
synchronized (playedCards) {
for (final List<WhiteCard> cards : playedCards.cards()) {
// TODO fix this for multiple played cards
for (final WhiteCard card : cards) {
whiteDeck.discard(card);
}
@ -825,20 +825,6 @@ public class Game {
}
dealState();
// HACK HACK
// for (final Player player : players) {
// if (player == getJudge()) {
// continue;
// }
// try {
// playedCards.addCard(player, whiteDeck.getNextCard());
// playedCards.addCard(player, whiteDeck.getNextCard());
// } catch (final OutOfCardsException ooce) {
// // pass
// }
// }
// judgingState();
}
public class TooManyPlayersException extends Exception {