Java 找不到";。“交易卡”;方法和";。洗牌;方法。
甲板级Java 找不到";。“交易卡”;方法和";。洗牌;方法。,java,blackjack,Java,Blackjack,甲板级 import java.util.ArrayList; import java.util.ListIterator; import java.util.Random; public class DeckOfCards { ArrayList deck = new ArrayList(); ListIterator deckIterator, tempDeckIterator; int suit; Random gen; // Constructor public DeckOfCard
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Random;
public class DeckOfCards
{
ArrayList deck = new ArrayList();
ListIterator deckIterator, tempDeckIterator;
int suit;
Random gen;
// Constructor
public DeckOfCards()
{
gen = new Random(); // use this in a later method
// for loop to create all cards in the deck
for(int i = 0; i < 52; i++)
{
if(i < 13)
{
suit = 0;
}
else if(i < 26)
{
suit = 1;
}
else if(i < 39)
{
suit = 2;
}
else
{
suit = 3;
}
// create and add the card to the deck
deck.add(new PlayingCard((i + 1) % 13, suit));
}
// shuffle the deck
for(int i = 0; i < 7; i++)
{
shuffleDeck();
}
//printDeck();
}
public void printDeck()
{
deckIterator = deck.listIterator();
while(deckIterator.hasNext())
{
System.out.println(deckIterator.next());
}
}
// shufle the deck of cards
public void shuffleDeck()
{
ArrayList tempDeck = new ArrayList(); // used to hold rhe shuffled cards
int pos; // the postion of the randomly generated card
while(deck.size() > 0)
{
// Generate the card
pos = gen.nextInt(deck.size());
tempDeck.add((PlayingCard)deck.get(pos));
deck.remove(pos);
}
// put all cards back into the deck
tempDeckIterator = tempDeck.listIterator();
while(tempDeckIterator.hasNext())
{
deck.add((PlayingCard)tempDeckIterator.next()); // top card from temp puts it in deck
}
}
// get top card from the deck
public PlayingCard getTopCard()
{
PlayingCard temp = (PlayingCard)deck.get(0);
deck.remove(0);
return temp;
}
// determine if any carsd are left int the deck
public boolean isEmpty()
{
if(deck.size() == 0)
{
return true;
}
else
{
return false;
}
}
import java.util.ArrayList;
导入java.util.ListIterator;
导入java.util.Random;
公营甲板
{
ArrayList deck=新的ArrayList();
ListIterator deckIterator,tempDeckIterator;
内服;
随机发电机;
//建造师
公共甲板
{
gen=new Random();//在以后的方法中使用
//for循环创建牌组中的所有牌
对于(int i=0;i<52;i++)
{
如果(i<13)
{
西服=0;
}
否则如果(i<26)
{
西服=1;
}
否则如果(i<39)
{
西服=2;
}
其他的
{
西装=3件;
}
//创建卡片并将其添加到卡片组
增加(新游戏卡((i+1)%13,套装));
}
//洗牌
对于(int i=0;i<7;i++)
{
shuffleDeck();
}
//printDeck();
}
公共空白打印组()
{
deckIterator=deck.listIterator();
while(deckIterator.hasNext())
{
System.out.println(deckIterator.next());
}
}
//舒弗牌
公共空间
{
ArrayList tempdack=new ArrayList();//用于存放洗牌的牌
int pos;//随机生成的卡的位置
while(deck.size()>0)
{
//生成卡片
pos=gen.nextInt(deck.size());
tempDeck.add((PlayingCard)deck.get(pos));
甲板。移除(位置);
}
//把所有的牌都放回牌组
tempDeckIterator=tempDeck.listIterator();
while(tempDeckIterator.hasNext())
{
deck.add((PlayingCard)tempDeckIterator.next());//来自temp的顶卡将其放入deck中
}
}
//从牌组中取出最上面的牌
公共播放卡getTopCard()
{
PlayingCard温度=(PlayingCard)牌组获取(0);
甲板。移除(0);
返回温度;
}
//确定甲板上是否有车辆遗留
公共布尔值为空()
{
if(deck.size()==0)
{
返回true;
}
其他的
{
返回false;
}
}
}
这是我的BlackJackGui课程。
这门课就是问题所在。
他们找不到符号“.dealcard”和“.shuffle”
我是否必须改变我的牌组课程,或者我可以解决它?
提前谢谢你的帮助
if (gameInProgress == false) {
message = "Click \"New Game\" to start a new game.";
repaint();
return;
}
playerHand.addCard( BJDeck.dealCard() );
if ( playerHand.getBlackjackValue() > 21 ) {
message = "You've busted! Sorry, you lose.";
gameInProgress = false;
}
else if (playerHand.getCardCount() == 5) {
message = "You win by taking 5 cards without going over 21.";
gameInProgress = false;
}
else {
message = "You have " + playerHand.getBlackjackValue() + ". Hit or Stand?";
}
repaint();
}
void doStand() {
// This method is called when the user clicks the "Stand!" button.
// Check whether a game is actually in progress. If it is,
// the game ends. The dealer takes cards until either the
// dealer has 5 cards or more than 16 points. Then the
// winner of the game is determined.
if (gameInProgress == false) {
message = "Click \"New Game\" to start a new game.";
repaint();
return;
}
gameInProgress = false;
while (dealerHand.getBlackjackValue() <= 16 && dealerHand.getCardCount() < 5)
dealerHand.addCard( BJDeck.dealCard() );
if (dealerHand.getBlackjackValue() > 21)
message = "You win! Dealer has busted with " + dealerHand.getBlackjackValue() + ".";
else if (dealerHand.getCardCount() == 5)
message = "Sorry, you lose. Dealer took 5 cards without going over 21.";
else if (dealerHand.getBlackjackValue() > playerHand.getBlackjackValue())
message = "Sorry, you lose, " + dealerHand.getBlackjackValue()
+ " to " + playerHand.getBlackjackValue() + ".";
else if (dealerHand.getBlackjackValue() == playerHand.getBlackjackValue())
message = "Sorry, you lose. Dealer wins on a tie.";
else
message = "You win, " + playerHand.getBlackjackValue()
+ " to " + dealerHand.getBlackjackValue() + "!";
repaint();
}
void doNewGame() {
// Called by the constructor, and called by actionPerformed() if
// the use clicks the "New Game" button. Start a new game.
// Deal two cards to each player. The game might end right then
// if one of the players had blackjack. Otherwise, gameInProgress
// is set to true and the game begins.
if (gameInProgress) {
// If the current game is not over, it is an error to try
// to start a new game.
message = "You still have to finish this game!";
repaint();
return;
}
DeckOfCards BJDeck = new DeckOfCards(); // Create the deck and hands to use for this game.
dealerHand = new BlackjackHand();
playerHand = new BlackjackHand();
BJDeck.shuffle();
dealerHand.addCard( BJDeck.dealCard() ); // Deal two cards to each player.
dealerHand.addCard( BJDeck.dealCard() );
playerHand.addCard( BJDeck.dealCard() );
playerHand.addCard( BJDeck.dealCard() );
if(gameInProgress==false){
message=“单击“新游戏”开始新游戏。”;
重新油漆();
返回;
}
playerHand.addCard(BJDeck.dealCard());
如果(playerHand.getBlackjackValue()>21){
message=“您失败了!对不起,您输了。”;
gameInProgress=false;
}
else if(playerHand.getCardCount()==5){
message=“您可以在不超过21张的情况下获得5张牌,从而获胜。”;
gameInProgress=false;
}
否则{
message=“您有“+playerHand.getBlackjackValue()+”。是打还是站?”;
}
重新油漆();
}
void doStand(){
//当用户单击“站立!”按钮时,将调用此方法。
//检查游戏是否正在进行。如果正在进行,
//游戏结束。发牌人接受牌,直到
//经销商有5张卡或超过16分。然后
//比赛的胜利者已经确定。
if(gameInProgress==false){
message=“单击“新游戏”开始新游戏。”;
重新油漆();
返回;
}
gameInProgress=false;
while(dealerHand.getBlackjackValue()21)
message=“您赢了!经销商已使用“+dealerHand.getBlackjackValue()+”终止交易”;
else if(dealerHand.getCardCount()==5)
message=“对不起,您输了。经销商未超过21张就拿走了5张卡。”;
else if(dealerHand.getBlackjackValue()>playerHand.getBlackjackValue())
message=“抱歉,您丢失了,”+dealerHand.getBlackjackValue()
+“到“+playerHand.getBlackjackValue()+”;
else if(dealerHand.getBlackjackValue()==playerHand.getBlackjackValue())
message=“对不起,您输了。平局时庄家赢。”;
其他的
message=“你赢了,”+playerHand.getBlackjackValue()
+到“+DealHand.getBlackjackValue()+”!”;
重新油漆();
}
void doNewGame(){
//由构造函数调用,如果
//用户点击“新游戏”按钮,开始新游戏。
//给每位玩家发两张牌。游戏可能就在那时结束
//如果其中一个玩家有21点,否则,gameInProgress
//设置为true,游戏开始。
如果(游戏进程){
//如果当前游戏尚未结束,则尝试是错误的
//开始一场新的比赛。
message=“您仍然必须完成此游戏!”;
重新油漆();
返回;
}
DeckOfCards BJDeck=新建DeckOfCards();//创建用于此游戏的牌组和手牌。
DealHand=新黑手();
playerHand=新的黑手();
BJDeck.shuffle();
dealerHand.addCard(BJDeck.dealCard());//给每位玩家发两张牌。
dealerHand.addCard(BJDeck.dealCard());
playerHand.addCard(BJDeck.dealCard());
playerHand.addCard(BJDeck.dealCard());
DeckOfCards
有名为getTopCard()
和shuffleDeck()
的方法,而不是dealCard()
和shuffle()
改变
BJDeck.shuffle();
到
及
到
错误在哪里(行号或可以指出代码片段中错误位置的东西)?您认为您在哪里声明了dealCard
方法或shuffle
方法?请仔细查看您实际声明的名称。
BJDeck.shuffleDeck();
dealerHand.addCard( BJDeck.dealCard() );
dealerHand.addCard( BJDeck.getTopCard() );