Exemplo n.º 1
0
 private void assignCards() {
   player.clearCards();
   dealer.clearCards();
   for (int i = 0; i < 3; ++i) {
     player.assignCard(genNewCard());
     dealer.assignCard(genNewCard());
   }
 }
Exemplo n.º 2
0
 private void judge() {
   if (player.numOfSpecialCards() > dealer.numOfSpecialCards()) {
     player.win();
     dealer.lose();
   } else if (player.numOfSpecialCards() < dealer.numOfSpecialCards()) {
     dealer.win();
     player.lose();
   } else {
     int playerScore = 0, dealerScore = 0;
     for (Card card : player.getCards()) {
       if (!card.isSpecial()) playerScore += card.getValue();
       playerScore %= 10;
     }
     for (Card card : dealer.getCards()) {
       if (!card.isSpecial()) dealerScore += card.getValue();
       dealerScore %= 10;
     }
     if (playerScore > dealerScore) {
       player.win();
       dealer.lose();
     } else {
       dealer.win();
       player.lose();
     }
   }
 }
Exemplo n.º 3
0
 /**
  * Update changing components.
  *
  * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
  */
 @Override
 public void paintComponent(Graphics g) {
   money.setText(String.valueOf(player.getMoney()));
   record.setText(String.valueOf(bestScore));
   dealerPanel.removeAll();
   playerPanel.removeAll();
   for (Card dealerCard : dealer.getCards()) dealerPanel.add(dealerCard);
   for (Card playerCard : player.getCards()) playerPanel.add(playerCard);
   revalidate();
 }