我正在尝试制作一个非常简单的二十一点游戏,我在从数组列表中抽牌并将它们放入玩家手和经销商手时遇到问题......
这是我到目前为止所拥有的,任何愿意提供帮助的人将不胜感激。
我也意识到我很多人没有以最有效的方式做到这一点......
卡片阵列列表
import java.util.ArrayList;
public class deck {
ArrayList<card> deck = new ArrayList<card>();
public deck () {
deck = new ArrayList<card>();
//Spades
deck.add(new card ("2", "Spades"));
deck.add(new card ("3", "Spades"));
deck.add(new card ("4", "Spades"));
deck.add(new card ("5", "Spades"));
deck.add(new card ("6", "Spades"));
deck.add(new card ("7", "Spades"));
deck.add(new card ("8", "Spades"));
deck.add(new card ("9", "Spades"));
deck.add(new card ("10", "Spades"));
deck.add(new card ("2", "Spades"));
deck.add(new card ("J", "Spades"));
deck.add(new card ("Q", "Spades"));
deck.add(new card ("K", "Spades"));
deck.add(new card ("A", "Spades"));
//Clubs
deck.add(new card ("2", "Clubs"));
deck.add(new card ("3", "Clubs"));
deck.add(new card ("4", "Clubs"));
deck.add(new card ("5", "Clubs"));
deck.add(new card ("6", "Clubs"));
deck.add(new card ("7", "Clubs"));
deck.add(new card ("8", "Clubs"));
deck.add(new card ("9", "Clubs"));
deck.add(new card ("10", "Clubs"));
deck.add(new card ("2", "Clubs"));
deck.add(new card ("J", "Clubs"));
deck.add(new card ("Q", "Clubs"));
deck.add(new card ("K", "Clubs"));
deck.add(new card ("A", "Clubs"));
//Hearts
deck.add(new card ("2", "Hearts"));
deck.add(new card ("3", "Hearts"));
deck.add(new card ("4", "Hearts"));
deck.add(new card ("5", "Hearts"));
deck.add(new card ("6", "Hearts"));
deck.add(new card ("7", "Hearts"));
deck.add(new card ("8", "Hearts"));
deck.add(new card ("9", "Hearts"));
deck.add(new card ("10", "Hearts"));
deck.add(new card ("2", "Hearts"));
deck.add(new card ("J", "Hearts"));
deck.add(new card ("Q", "Hearts"));
deck.add(new card ("K", "Hearts"));
deck.add(new card ("A", "Hearts"));
//Diamonds
deck.add(new card ("2", "Diamonds"));
deck.add(new card ("3", "Diamonds"));
deck.add(new card ("4", "Diamonds"));
deck.add(new card ("5", "Diamonds"));
deck.add(new card ("6", "Diamonds"));
deck.add(new card ("7", "Diamonds"));
deck.add(new card ("8", "Diamonds"));
deck.add(new card ("9", "Diamonds"));
deck.add(new card ("10", "Diamonds"));
deck.add(new card ("2", "Diamonds"));
deck.add(new card ("J", "Diamonds"));
deck.add(new card ("Q", "Diamonds"));
deck.add(new card ("K", "Diamonds"));
deck.add(new card ("A", "Diamonds"));
}
public ArrayList<card> getCards(){
return deck;
}
public card deal(){
card one = deck.get((int) (Math.random() * deck.size()));
deck.remove(one);
return one;
}
}
玩家和经销商手类
这是我希望用数组中的两张随机卡填充 dealPlayer() 和 dealDealer() 的地方,我现在只是在树桩上,似乎无法弄清楚任何可行的方法......提前谢谢帮助,如果还有什么我需要发布的,请告诉我!
import java.util.ArrayList;
public class dealer {
deck deck = new deck();
String dealerTopCardString = "";
card playerHandCard;
card dealerHandCard;
ArrayList<card> dealerHand = new ArrayList<card>();
ArrayList<card> playerHand = new ArrayList<card>();
public void start() {
dealerHand = new ArrayList<card>();
playerHand = new ArrayList<card>();
}
public void dealPlayer() {
//LOOKING FOR HELP HERE
}
public void dealDealer() {
//LOOKING FOR HELP HERE
}
public String getPlayerHand() {
String playerHandString = "";
for (int i = 0; i < playerHand.size(); i++)
playerHandCard = playerHand.get(i);
card card = new card(playerHandCard.getValue(), playerHandCard.getSuit());
playerHandString += "\n";
playerHandString += card.getValue();
playerHandString += "\t";
playerHandString += card.getSuit();
return playerHandString;
}
public String getDealerHand() {
String dealerHandString = "";
for (int i = 0; i < dealerHand.size(); i++)
dealerHandCard = dealerHand.get(i);
card card = new card(dealerHandCard.getValue(), dealerHandCard.getSuit());
dealerHandString += "\n";
dealerHandString += card.getValue();
dealerHandString += "\t";
dealerHandString += card.getSuit();
return dealerHandString;
}
public String getDealerTopCard(){
return getDealerTopCard;
}
public int getPlayerHandValue(){
return getPlayerHandValue;
}
public int getDealerHandValue(){
return getDealerHandValue;
}
public void resetDealerHand(){
dealerHand.clear();
}
public void resetPlayerHand(){
playerHand.clear();
}
}