【发布时间】:2014-12-09 04:42:22
【问题描述】:
试图用Java创建一个二十一点游戏,但无法理解如何从数组事物中获取数值。
这是我的纸牌代码:
//Represent a playing card
public class Card
{
//Instance variables:
int suit; //0=clubs, 1=diamonds, 2=hearts, 3=spades
int rank; //1=ace, 2=2,..., 10=10, 11=J, 12=Q, 13=K
//Constructor:
public Card (int theSuit, int theRank)
{
suit = theSuit;
rank = theRank;
}
//Print the card in a human-readable form:
public void printCard()
{
String[] suits = {"Clubs", "Diamonds", "Hearts", "Spades"};
String[] ranks = {"narf", "Ace", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Jack", "Queen", "King"};
System.out.print(ranks[rank] + " of " + suits[suit]);
}
}
看到我用过 Card CardOne = deck.cards[(int) (Math.random() * 52)];获得第一张和第二张牌供玩家查看,但我正在努力弄清楚如何将卡片的价值保存为整数(红桃 4 为 4,黑桃 J 为 10 等)为整数用于确定玩家多少分的值?
对不起,如果这令人困惑,英语不是我的第一语言。
提前致谢!
-约翰
【问题讨论】: