예제 #1
0
  public JSONObject toJSON() {
    JSONObject json = new JSONObject();

    json.put("name", name);
    json.put("playerId", playerId);
    json.put("hero", hero.toJSON());
    if (mana != maxMana) json.put("mana", mana);
    if (maxMana > 0) json.put("maxMana", maxMana);
    json.put("deckPos", deckPos);
    if (overload > 0) json.put("overload", overload);
    if (fatigueDamage > 0) json.put("fatigueDamage", fatigueDamage);

    if (minions.size() > 0) {
      JSONArray array = new JSONArray();
      for (Minion minion : minions) {
        array.put(minion.toJSON());
      }
      json.put("minions", array);
    }

    if (hand.size() > 0) {
      JSONArray array = new JSONArray();
      for (Card card : hand) {
        array.put(card.toJSON());
      }
      json.put("hand", array);
    }

    if (numCardsUsed > 0) {
      json.put("numCardsUsed", numCardsUsed);
    }

    return json;
  }
예제 #2
0
 @Override
 public int hashCode() {
   int hash = 1;
   hash = hash * 31 + (null == name ? 0 : name.hashCode());
   hash = hash * 31 + playerId;
   hash = hash * 31 + (null == hero ? 0 : hero.hashCode());
   hash = hash * 31 + (null == deck ? 0 : deck.hashCode());
   hash = hash * 31 + mana;
   hash = hash * 31 + maxMana;
   hash = hash * 31 + deckPos;
   hash = hash * 31 + fatigueDamage;
   hash = hash * 31 + (null == minions ? 0 : minions.hashCode());
   hash = hash * 31 + (null == hand ? 0 : hand.hashCode());
   hash = hash * 31 + overload;
   hash = hash * 31 + numCardsUsed;
   return hash;
 }
예제 #3
0
  @Override
  public boolean equals(Object other) {

    if (other == null) return false;

    if (this.getClass() != other.getClass()) return false;

    PlayerModel otherPlayer = (PlayerModel) other;

    if (playerId != otherPlayer.playerId) return false;
    if (mana != otherPlayer.mana) return false;
    if (maxMana != otherPlayer.maxMana) return false;
    if (overload != otherPlayer.overload) return false;
    if (deckPos != otherPlayer.deckPos) return false;
    if (fatigueDamage != otherPlayer.fatigueDamage) return false;

    if (!name.equals(otherPlayer.name)) return false;
    if (!hero.equals(otherPlayer.hero)) return false;
    if (deck != null && !deck.equals(otherPlayer.deck)) return false;
    if (!minions.equals(otherPlayer.minions)) return false;
    if (!hand.equals(otherPlayer.hand)) return false;
    if (numCardsUsed != otherPlayer.numCardsUsed) return false;
    return true;
  }
예제 #4
0
 public void placeCardHand(Card card) {
   if (hand.isFull()) return;
   card.setInHand(true);
   hand.add(card);
 }