Bugfix: assign unique (negative) ids to blank cards; previously the wrong card could win if multiple blanks were being judged in the same round.
This commit is contained in:
parent
d0e8e1e33f
commit
be47508843
|
@ -341,7 +341,7 @@ cah.inherits(cah.card.WhiteCard, cah.card.BaseCard);
|
|||
* @returns True if this is a blank card.
|
||||
*/
|
||||
cah.card.WhiteCard.prototype.isBlankCard = function() {
|
||||
return this.getServerId() == 0;
|
||||
return this.getServerId() < -1;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -476,7 +476,7 @@ cah.Game.prototype.setRoundWhiteCards = function(cardSets) {
|
|||
var cardData = cardSets[setIndex][index];
|
||||
var card;
|
||||
var id = cardData[cah.$.WhiteCardData.ID];
|
||||
if (id >= 0) {
|
||||
if (id != -1) {
|
||||
card = new cah.card.WhiteCard(true, id);
|
||||
card.setText(cardData[cah.$.WhiteCardData.TEXT]);
|
||||
card.setWatermark(cardData[cah.$.WhiteCardData.WATERMARK]);
|
||||
|
@ -947,17 +947,17 @@ cah.Game.prototype.confirmClick_ = function() {
|
|||
}
|
||||
} else {
|
||||
if (this.handSelectedCard_ != null) {
|
||||
var ajax = cah.Ajax.build(cah.$.AjaxOperation.PLAY_CARD).withGameId(this.id_).withCardId(
|
||||
this.handSelectedCard_.getServerId());
|
||||
if (this.handSelectedCard_.isBlankCard()) {
|
||||
// blank card
|
||||
var text = prompt("What would you like this card to say?", "");
|
||||
if (text == null || text == '') { return; }
|
||||
text = $("<div/>").text(text).html(); // html sanitise
|
||||
this.handSelectedCard_.setText(text);
|
||||
cah.Ajax.build(cah.$.AjaxOperation.PLAY_CARD).withGameId(this.id_).withCardId(0).withMessage(text).run();
|
||||
} else {
|
||||
cah.Ajax.build(cah.$.AjaxOperation.PLAY_CARD).withGameId(this.id_).withCardId(
|
||||
this.handSelectedCard_.getServerId()).run();
|
||||
ajax = ajax.withMessage(text);
|
||||
}
|
||||
ajax.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1209,8 +1209,6 @@ public class Game {
|
|||
playCard = card;
|
||||
if (WhiteDeck.isBlankCard(card)) {
|
||||
playCard.setText(cardText);
|
||||
// note that since blank cards are indistinguishable to the server, we might end up
|
||||
// removing a different card than the client did. but this shouldn't break anything.
|
||||
}
|
||||
// remove the card from their hand. the client will also do so when we return
|
||||
// success, so no need to tell it to do so here.
|
||||
|
|
|
@ -45,6 +45,7 @@ public class WhiteDeck {
|
|||
private final List<WhiteCard> deck;
|
||||
private final List<WhiteCard> dealt;
|
||||
private final List<WhiteCard> discard;
|
||||
private int lastBlankCardId = -1;
|
||||
|
||||
/**
|
||||
* Create a new white card deck, loading the cards from the database and shuffling them.
|
||||
|
@ -89,13 +90,12 @@ public class WhiteDeck {
|
|||
public synchronized void discard(final WhiteCard card) {
|
||||
if (card != null) {
|
||||
if (isBlankCard(card)) {
|
||||
// create a fresh blank card to ensure player text is cleared
|
||||
discard.add(createBlankCard());
|
||||
} else {
|
||||
discard.add(card);
|
||||
card.setText("____"); // clear any player text
|
||||
}
|
||||
discard.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles the discard pile and puts the cards under the cards remaining in the deck.
|
||||
|
@ -113,7 +113,7 @@ public class WhiteDeck {
|
|||
*/
|
||||
private WhiteCard createBlankCard() {
|
||||
final WhiteCard blank = new WhiteCard();
|
||||
blank.setId(0);
|
||||
blank.setId(--lastBlankCardId);
|
||||
blank.setText("____");
|
||||
blank.setWatermark("____");
|
||||
return blank;
|
||||
|
@ -127,6 +127,6 @@ public class WhiteDeck {
|
|||
* @return True if the card is a blank card.
|
||||
*/
|
||||
public static boolean isBlankCard(final WhiteCard card) {
|
||||
return card.getId() == 0;
|
||||
return card.getId() < -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue