任何????嗨,在我的黑杰克游戏中,我首先要求玩家加倍分裂,如果他拒绝,那么我允许他分裂:
while(true){
for(int j=0;j<2;j++){
if(players[i].splits[j].getStatus() != true){ // splits is an array of two players hand 1 and hand 2
System.out.print("Choose your next move, " + players[i].name + ", Hand "+ players[i].splits[j].number + ": \n" + "Points: " + players[i].splits[j].points + "\n" + "Hint: ");
getHints(players[i].splits[j]);
System.out.print( "\n1)Hit\n2)Stand\n");
System.out.println();
x2 = IO.readInt();
if (x2==2){
players[i].splits[j].standed = true; // if player stand...
break;
}else if(x2 == 1){//else deal a card
Card c = dealCard(deck);
updatePoints(players[i].splits[j], c);
addCard(players[i].splits[j], c);
System.out.println(players[i].name + ", Hand "+ players[i].splits[j].number + " was dealt: " + c.showCardValue() + " of " + c.showCardSuit() );
boolean isBusted = testPoints(players[i].splits, j); // test for busted
if (isBusted == true){
System.out.println("BUSTED!!!!!!!!!");
players[i].splits[j].busted = true;
break;
}
}
}
System.out.println(players[i].name + ", Hand " + players[i].splits[j].number + " Points: "+ players[i].splits[j].points);
// printStats(players[i].splits[j]);
}
//check to end loop if split is busted to stands...
}
当我打印玩家统计数据时,我得到的是内存位置而不是文本,任何人都可以帮忙。谢谢,如果您需要更多信息请说明,以便我可以更新。
=======
输出:3是玩家名称... 10是发出的牌,是分裂......
Choose your next move, 3, Hand 1:
Points: 10
Hint: You have a 0% chance of busting
1)Hit
2)Stand
1
3, Hand 1 was dealt: Ten of Spades
3, Hand 1 Points: 20
Choose your next move, 3, Hand 2:
Points: 10
Hint: You have a 0% chance of busting
1)Hit
2)Stand
1
3, Hand 2 was dealt: Five of Diamonds
3, Hand 2 Points: 15
Choose your next move, 3, Hand 1:
Points: 20
Hint: You have a 92% chance of busting
1)Hit
2)Stand
2
3, Hand 1 Points: 20
Choose your next move, 3, Hand 2:
Points: 15
Hint: You have a 58% chance of busting
1)Hit
2)Stand
2
3, Hand 1 : Points splitPlayer@1a758cb
Previous Cards dealt:
Ten of Spades
Five of Diamonds
splitPlayer类:
public class splitPlayer {
public int points = 0;
boolean busted = false;
boolean standed = false;
int number = 0;
int ace = 0;
String name = "";
Card[] cardsDealt = new Card[12];
public splitPlayer(int number, int points){
this.number = number;
this.name = "Hand "+ number;
this.points = points;
}
public boolean getStatus(){
if(busted == true || standed == true ){
return true;
}else{
return false;
}
}
public void setPoints(int points){
this.points += points;
}
}
======
updatePoints:
public static void updatePoints(splitPlayer player, Card c){
int point = c.getValue();
if (point == 1){
player.ace += 1;
player.setPoints(11);
}else{
player.setPoints(point);
}
if (player.points > 21 && player.ace > 0) {
player.points -= 10;
player.ace --;
}
return;
}
答案 0 :(得分:1)
罪魁祸首似乎是这行代码:
System.out.println(players[i].name + ", Hand " + players[i].splits[j].number + " Points: "+ players[i].splits[j].points);
要弄清楚出了什么问题,您需要知道players[i].splits[j].points
的类型。根据输出,它似乎是splitPlayer
类的一个实例。您可以通过重载此类的toString()
方法来解决问题。如果没有确认上面的代码行确实导致问题,我无法确定。我还需要查看更多代码,特别是此处使用的points
数据成员的声明。
<强>附录:强>
您在输出中看到splitPlayer@1a758cb
的原因是因为您将对象与String
连接在一起。 Java将自动调用该对象的toString()
方法。如果对象的类没有提供toString()
方法,则会调用Object
中的方法,它会给出您看到的输出。