// 初始化一个IC卡
 private Card initIC() {
   Card card = new Card();
   card.setCardNo("1100010001000");
   card.setFreeMoney(100000); // 一千元
   card.setSteadyMoney(80000); // 八百元
   return card;
 }
Beispiel #2
0
  public void draw(int n) {
    Card[] temp = new Card[hand.length + n];
    int i;
    for (i = 0; i < hand.length; i++) {
      temp[i] = hand[i];
    }
    for (; i < hand.length + n; i++) {
      boolean found = true;
      Card c = new Card();
      ;
      while (found) {
        c = new Card();
        found = false;
        for (int k = 0; k < i; k++) {
          if (temp[k].getID() == c.getID()) {
            found = true;
            break;
          }
        }
      }

      temp[i] = c;
    }

    hand = temp;
  }
Beispiel #3
0
 /**
  * Notify user which suit must be played
  *
  * @param cardsPlayed cards played for current turn
  * @param veryFirstTurn indicator whether this is a very first turn
  * @param myHand
  */
 private void notifyPlayableSuit(
     List<Card> cardsPlayed, boolean veryFirstTurn, List<Card> myHand) {
   Iterator<Card> searchHand = myHand.iterator();
   boolean found = false;
   while (searchHand.hasNext() && found == false) {
     Card card = searchHand.next();
     if (veryFirstTurn) // player 1 in first trick of a round
     {
       found = true;
       System.out.println("(You must lead with the Duece of Clubs)");
     } else {
       if (cardsPlayed.size() > 0) // players 2-4
       {
         Suit suitLed = cardsPlayed.get(0).getSuit();
         if (card.getSuit().equals(suitLed)) // user holds a suit matching first suit played
         {
           found = true;
           System.out.println("(You must play " + suitLed + ")");
         }
       } else {
         found = true;
         System.out.println("(You can lead with any card)");
       }
     }
   }
 }
Beispiel #4
0
 public boolean isSlap() {
   int potSize = stackPot.size();
   boolean pair = potSize >= 2 && Card.getRank(stackPot.get(0)) == Card.getRank(stackPot.get(1));
   boolean sandwich =
       potSize >= 3 && Card.getRank(stackPot.get(0)) == Card.getRank(stackPot.get(2));
   return pair || sandwich;
 }
Beispiel #5
0
 private void hit(Player p) {
   Card drawn = drawCard();
   int value = drawn.getValue();
   String sval;
   if (value > 2 && value < 11) {
     sval = value + "";
   } else if (value == 11) {
     sval = "Jack";
     value = 10;
   } else if (value == 12) {
     sval = "Queen";
     value = 10;
   } else if (value == 13) {
     sval = "King";
     value = 10;
   } else {
     sval = "Ace";
     if (p.getScore() <= 10) {
       value = 11;
     }
   }
   p.add(value);
   String suit = drawn.getSuit();
   io.print(p.getName() + " drew the " + sval + " of " + suit + ".");
   io.print(p.getName() + "'s score is currently " + p.getScore());
 }
Beispiel #6
0
 // aces counted as 1 point
 public static int getCardsValueNoAces(Cards cards) {
   int value = 0;
   for (Card c : cards.getCards()) {
     value += c.getRankInInt();
   }
   return value;
 }
 @Override
 public void execute() {
   Card card = null;
   if (container instanceof Field) {
     Field field = (Field) container;
     if (item instanceof Card) {
       card = (Card) item;
       field.removeItem();
     } else if (item instanceof OverRay) {
       OverRay overRay = (OverRay) item;
       Card topCard = overRay.getOverRayCards().topCard();
       overRay.getOverRayCards().remove(topCard);
       if (overRay.getOverRayCards().size() == 0) {
         field.removeItem();
       }
     }
   } else if (container instanceof HandCards) {
     card = (Card) item;
     ((HandCards) container).getCardList().remove(card);
   }
   if (card != null) {
     card.set();
     Deck banished = (Deck) duel.getDuelFields().getField(FieldType.BANISHED).getItem();
     banished.getCardList().push(card, true);
     duel.unSelect();
   }
 }
 /**
  * getTokenCreatures.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getTokenCreatures(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.isCreature() && c.isToken() && !c.isEquipped() && !c.isEnchanted()) ret.add(c);
   }
   return ret;
 }
 /**
  * getGlobalEnchantments.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getGlobalEnchantments(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.isGlobalEnchantment() && !c.isCreature()) ret.add(c);
   }
   return ret;
 }
 public String toString() {
   StringBuilder ans = new StringBuilder();
   for (Card c : cardList) {
     ans.append(c.toString());
   }
   return ans.toString();
 }
 /**
  * getPlaneswalkers.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getPlaneswalkers(ArrayList<Card> cards) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.isPlaneswalker() && !c.isArtifact()) ret.add(c);
   }
   return ret;
 }
 private int numDifferentSuits() {
   Set<Character> suits = new HashSet<Character>();
   for (Card c : this.cardList) {
     suits.add(c.getSuit().charAt(0));
   }
   return suits.size();
 }
  public String getXML() {
    String xml = "";
    xml += "<?xml version= \"1.0\"?>\n";
    xml += "<deck>\n";

    String type = "deck";
    if (this instanceof HeroDeck) {
      type = "herodeck";
    }
    if (this instanceof VillainDeck) {
      type = "villaindeck";
    }
    if (this instanceof EnvironmentDeck) {
      type = "environmentdeck";
    }
    xml += " <type>" + type + "</type>\n";

    for (Card c : cards) {
      xml += c.getXML();
    }

    xml += "</deck>\n";
    xml += "</xml>\n";

    return xml;
  }
Beispiel #14
0
 public int calculateHandCardScore() {
   int score = 0;
   for (Card cd : HandCards.keySet()) {
     score += cd.getPoint();
   }
   return score;
 }
Beispiel #15
0
  private TaskData doInBackgroundAnswerCard(TaskData... params) {
    long start, stop;
    Deck deck = params[0].getDeck();
    Card oldCard = params[0].getCard();
    int ease = params[0].getInt();
    Card newCard;

    if (oldCard != null) {
      start = System.currentTimeMillis();
      oldCard.temporarilySetLowestPriority();
      deck.decreaseCounts(oldCard);
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackground - Set old card 0 priority in " + (stop - start) + " ms.");
    }

    start = System.currentTimeMillis();
    newCard = deck.getCard();
    stop = System.currentTimeMillis();
    Log.v(TAG, "doInBackground - Loaded new card in " + (stop - start) + " ms.");
    publishProgress(new TaskData(newCard));

    if (ease != 0 && oldCard != null) {
      start = System.currentTimeMillis();
      deck.answerCard(oldCard, ease);
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackground - Answered old card in " + (stop - start) + " ms.");
    }

    return null;
  }
 /**
  * getCard.
  *
  * @param cards a {@link java.util.ArrayList} object.
  * @param name a {@link java.lang.String} object.
  * @return a {@link java.util.ArrayList} object.
  */
 public static ArrayList<Card> getCard(ArrayList<Card> cards, String name) {
   ArrayList<Card> ret = new ArrayList<Card>();
   for (Card c : cards) {
     if (c.getName().equals(name)) ret.add(c);
   }
   return ret;
 }
 private static boolean contains(Collection<Card> coll, Card.Color c, Card.Value v) {
   for (Iterator<Card> itr = coll.iterator(); itr.hasNext(); ) {
     Card card = itr.next();
     if (card.getColor() == c && card.getValue() == v) return true;
   }
   return false;
 }
  /**
   * getBasics.
   *
   * @param cards a {@link java.util.ArrayList} object.
   * @param color a {@link java.lang.String} object.
   * @return a {@link java.util.ArrayList} object.
   */
  public static ArrayList<Card> getBasics(ArrayList<Card> cards, String color) {
    ArrayList<Card> ret = new ArrayList<Card>();

    for (Card c : cards) {
      String name = c.getName();

      if (c.isEnchanted()) ; // do nothing
      else if (name.equals("Swamp") || name.equals("Bog")) {
        if (color == Constant.Color.Black) {
          ret.add(c);
        }
      } else if (name.equals("Forest") || name.equals("Grass")) {
        if (color == Constant.Color.Green) {
          ret.add(c);
        }

      } else if (name.equals("Plains") || name.equals("White Sand")) {
        if (color == Constant.Color.White) {
          ret.add(c);
        }

      } else if (name.equals("Mountain") || name.equals("Rock")) {
        if (color == Constant.Color.Red) {
          ret.add(c);
        }

      } else if (name.equals("Island") || name.equals("Underwater")) {
        if (color == Constant.Color.Blue) {
          ret.add(c);
        }
      }
    }

    return ret;
  }
 public int giveValue() {
   int tmp = this.tableCards.get(1).getSuite();
   for (Card c : this.tableCards) {
     if (tmp != c.getSuite()) return 0;
   }
   return 2;
 }
  /**
   * getNonBasicLand.
   *
   * @param cards a {@link java.util.ArrayList} object.
   * @param landName a {@link java.lang.String} object.
   * @return a {@link java.util.ArrayList} object.
   */
  public static ArrayList<Card> getNonBasicLand(ArrayList<Card> cards, String landName) {
    ArrayList<Card> ret = new ArrayList<Card>();

    for (Card c : cards) if (c.getName().equals(landName)) ret.add(c);

    return ret;
  }
Beispiel #21
0
  @Override
  public boolean attempt(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
    int successes = 0;
    Set cause = parameters.get(Parameter.CAUSE);
    int required = 1;
    if (parameters.containsKey(Parameter.NUMBER))
      required = Sum.get(parameters.get(Parameter.NUMBER));

    for (Player player : parameters.get(Parameter.PLAYER).getAll(Player.class)) {
      java.util.Set<Card> cards = null;
      if (parameters.containsKey(Parameter.CHOICE))
        cards = parameters.get(Parameter.CHOICE).getAll(Card.class);
      else cards = new Set(player.getHand(game.actualState).objects).getAll(Card.class);

      successes = 0;
      for (Card thisCard : cards) {
        java.util.Map<Parameter, Set> newParameters = new java.util.HashMap<Parameter, Set>();
        newParameters.put(Parameter.CAUSE, cause);
        newParameters.put(Parameter.CARD, new Set(thisCard));
        if (createEvent(
                game,
                thisCard.getOwner(game.actualState) + " discards " + thisCard + ".",
                DISCARD_ONE_CARD,
                newParameters)
            .attempt(event)) successes++;

        if (successes == required) break;
      }
      if (successes != required) return false;
    }
    return true;
  }
Beispiel #22
0
 @Test
 public void testGetCash()
     throws NotEnoughMoneyInAccountException, NotEnoughMoneyInATMException,
         NoCardInsertedException {
   System.out.println("getCashNotZeroBalance");
   double atmMoney = 1000.0;
   ATM atmTest = new ATM(atmMoney);
   Card mockCard = mock(Card.class);
   Account mockAccount = mock(Account.class);
   atmTest.insertCard(mockCard); // ver.2
   double balance = 600.0;
   double amount = 100.0;
   int pinCode = 7777;
   when(mockCard.getAccount()).thenReturn(mockAccount);
   when(mockCard.checkPin(pinCode)).thenReturn(true);
   when(mockCard.isBlocked()).thenReturn(false);
   when(mockAccount.getBalance()).thenReturn(balance);
   when(mockAccount.withdrow(amount)).thenReturn(amount);
   atmTest.validateCard(mockCard, pinCode);
   atmTest.getCash(amount);
   when(mockAccount.getBalance()).thenReturn(balance - amount);
   assertEquals(atmTest.getMoneyInATM(), atmMoney - amount, 0.0);
   assertEquals(atmTest.checkBalance(), balance - amount, 0.0);
   InOrder inOrder = inOrder(mockCard, mockAccount);
   inOrder.verify(mockCard).isBlocked();
   inOrder.verify(mockCard).checkPin(pinCode);
   inOrder.verify(mockCard, atLeastOnce()).getAccount();
   verify(mockAccount).withdrow(amount);
   inOrder.verify(mockAccount).getBalance();
 }
  /**
   * Print Body - Prints the body of the XML document
   *
   * @param cardDeck a list of cards to be printed
   * @param PrintWriter so it prints to the same file
   */
  public void printBody(PrintWriter out, ArrayList<Card> cardDeck) {
    // Output the Root Element
    out.write("<carddeck version=\"1.0\">");
    out.println();

    for (int i = 0; i < cardDeck.size(); i++) {
      Card c = cardDeck.get(i);
      // Begin the card
      out.write("\t" + "<card>");
      out.println();
      // Output the Title
      out.write("\t\t" + "<title>" + replaceSpecial(c.getTitle()) + "</title>");
      out.println();
      // Output the Front
      out.write("\t\t" + "<front>" + replaceSpecial(c.getFront()) + "</front>");
      out.println();
      // Output the Back
      out.write("\t\t" + "<back>" + replaceSpecial(c.getBack()) + "</back>");
      out.println();
      // End the Card
      out.write("\t" + "</card>");
      out.println();
    }

    // Output The End of the Root Element
    out.write("</carddeck>");
    out.println();
  }
 private double calculatePotentialVAndT(
     int roundedTime,
     int needRounds,
     Hand currentHand,
     int[][] rankings,
     HashMap<String, Boolean> exsiting,
     int[] types) {
   if (roundedTime < needRounds) {
     double value = 0;
     for (int i = 0; i < Card.NO_OF_RANKS; ++i) {
       for (int j = 0; j < Card.NO_OF_SUITS; ++j) {
         if (rankings[i][j] == 0) {
           Card newCard = new Card(i, j);
           Hand newHand = new Hand(currentHand.toString() + ' ' + newCard.toString());
           rankings[i][j] = 1;
           //                        System.out.println(newHand.toString());
           value +=
               calculatePotentialVAndT(
                   roundedTime + 1, needRounds, newHand, rankings, exsiting, types);
           rankings[i][j] = 0;
         }
       }
     }
     return value;
   } else {
     if (exsiting.containsKey(currentHand.toString())) {
       return 0;
     }
     exsiting.put(currentHand.toString(), true);
     types[calculateHandType(currentHand)]++;
     return calculateHandValue(currentHand);
   }
 }
  @Test
  public void testPopulate() {
    assertEquals(116, Card.findAll().size());

    assertEquals(14, Card.findAll(costRange.TWO).size());
    assertEquals(53, Card.findAll(costRange.THREE_FOUR).size());
    assertEquals(49, Card.findAll(costRange.FIVE_PLUS).size());

    Kingdom set = Kingdom.find("byName", "Test").first();
    assertNotNull(set);
    assertEquals("Test", set.name);

    Card embargo = Card.find("byName", "Embargo").first();
    assertNotNull(embargo);
    assertEquals("Embargo", embargo.name);
    assertEquals(2, embargo.cost);
    assertEquals(0, embargo.miscCost);
    assertEquals(expansionSet.SEASIDE, embargo.set);
    assertEquals("seaside/embargo.jpg", embargo.image);

    set.addAlwaysIn(embargo);
    assertEquals(1, set.alwaysIn.size());
    assertEquals(embargo, set.alwaysIn.get(0));

    set.completeKingdom();
    set.save();
    assertTrue(set.currentCards.contains(embargo));
    assertEquals(10, set.currentCards.size());

    for (Card card : set.currentCards) {
      System.out.println(card.cost + ": " + card.name + ", " + card.image);
    }
  }
Beispiel #26
0
  CardCollection addCards(
      CardCollection oldCards, Iterable<Card> cardsToAdd, TrackableProperty key) {
    if (cardsToAdd == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    if (oldCards == null) {
      oldCards = new CardCollection();
    }
    boolean needFlagAsChanged = false;
    for (Card c : cardsToAdd) {
      if (c != null && oldCards.add(c)) {
        if (views == null) {
          views = new TrackableCollection<CardView>();
          views.add(c.getView());
          set(key, views);
        } else if (views.add(c.getView())) {
          needFlagAsChanged = true;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
  @Test
  public void testNumCards() {

    List<Card> deck = makeDeck();
    Card tmpCard;

    Hand aHand =
        new Hand(
            1
                + " "
                + deck.remove(0)
                + " "
                + deck.remove(0)
                + " "
                + deck.remove(0)
                + " "
                + deck.remove(0)
                + " "
                + deck.remove(0));

    assertTrue(aHand.isComplete());

    try {
      tmpCard = deck.remove(0);
      aHand.addCard(tmpCard.getRank(), tmpCard.getSuit());
    } catch (Exception e) {
      fail("hand exception");
    }
  }
Beispiel #28
0
  CardCollection removeCards(
      CardCollection oldCards, Iterable<Card> cardsToRemove, TrackableProperty key) {
    if (cardsToRemove == null || oldCards == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    boolean needFlagAsChanged = false;
    for (Card c : cardsToRemove) {
      if (oldCards.remove(c)) {
        if (views == null) {
          set(key, null);
        } else if (views.remove(c.getView())) {
          if (views.isEmpty()) {
            views = null;
            set(key, null); // avoid keeping around an empty collection
            needFlagAsChanged = false; // doesn't need to be flagged a second time
          } else {
            needFlagAsChanged = true;
          }
        }
        if (oldCards.isEmpty()) {
          oldCards = null; // avoid keeping around an empty collection
          break;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
Beispiel #29
0
  public CardPanel(Card card) {
    // Prueba Borrar
    String colorCard;
    this.card = card;
    String cardColor = card.getColor(), cardType = card.getType(), imagePath = null;

    if (cardColor != null) {
      setBackground(getColor(cardColor));
    }

    if (cardType.equals("Number")) {
      imagePath = card.getNumber();
      System.out.print("Numero " + imagePath);

    } else {
      imagePath = card.getType();
    }

    setSize(150, 200);
    try {
      image = ImageIO.read(new File(imagePath + ".png"));
    } catch (IOException e) {
      System.out.println("Error IO " + imagePath);
      System.out.println(" largo " + cardType.length());
    }
  }
Beispiel #30
0
 public int getTotalHandScore() {
   int totalScore = 0;
   for (Card c : this.cards) {
     totalScore += c.getHighestValue();
   }
   return totalScore;
 }