Java扑克游戏程序
我正在做这个扑克游戏项目,我一直在研究如何打印卡片类型和函数末尾的默认“对不起,你输了”。我不确定我的代码是否正确,我将感谢任何类型的帮助 基本上,我的程序需要打印出来:Java扑克游戏程序,java,Java,我正在做这个扑克游戏项目,我一直在研究如何打印卡片类型和函数末尾的默认“对不起,你输了”。我不确定我的代码是否正确,我将感谢任何类型的帮助 基本上,我的程序需要打印出来: [A Spades, 10 Spades, Q Spades, J Spades, K Spades] Royal Flush! -------------------------------------------------- [9 Spades, 10 S
[A Spades, 10 Spades, Q Spades, J Spades, K Spades]
Royal Flush!
--------------------------------------------------
[9 Spades, 10 Spades, Q Spades, J Spades, K Spades]
Straight Flush!
--------------------------------------------------
等等
但我的程序只打印出:
[A Spades, 10 Spades, Q Spades, J Spades, K Spades]
我打印字体时遇到问题(皇家同花顺部分)
/**
*必须使用乘法器和goodHandTypes数组检查当前currentHand
*在函数末尾打印您的手写体(默认为“对不起,您丢失了”)。
*这可以通过testCheckHands()和main()方法进行检查。
*/
私人无效支票{
//实施这个方法!
List sortedHand=新阵列列表(currentHand);
Collections.sort(sortedHand,newcomparator(){
@凌驾
公共整数比较(卡卡1、卡2){
int rank1=card1.getRank();
int rank2=card2.getRank();
如果(rank1>rank2){
返回1;
}
如果(rank1
我已经有了所有的方法,我只需要帮助找到一种打印方法:
private boolean isStraight() {
for (int i = 0; i < numberOfCards; i++) {
if (currentHand.get(i).getRank() != currentHand.get(i + 1).getRank()) {
return false;
}
}
return true;
}
private boolean isFlush() {
for (int i = 0; i < numberOfCards; i++) {
if (currentHand.get(i).getSuit() != currentHand.get(i + 1).getSuit()) {
return false;
}
}
return true;
}
private boolean isStraightFlush() {
if (isStraight() == true && isFlush() == true) {
return true;
}
return false;
}
private boolean isRoyalFlush() {
if (isFlush() == false || isStraight() == false) {
return false;
} else {
if (currentHand.get(0).getRank() == 10) {
return true;
}
return false;
}
}
private boolean isFourOfAKind() {
//runs thru the hand for exactly 4 matches
for (int i = 0; i < numberOfCards - 1; i++) {
int counter = 0;
for (int y = i + 1; y < numberOfCards; y++) {
if (currentHand.get(i).getRank() == currentHand.get(0).getRank()) {
counter++;
}
}
if (counter == 4) {
return true;
} else {
return false;
}
}
return false;
}
private boolean isFullHouse() {
if (isThreeOfAKind() == true && isOnePair() == true) {
return true;
} else {
return false;
}
}
private boolean isThreeOfAKind() {
//matches three
for (int i = 0; i < numberOfCards; i++) {
int counter = 0;
for (int y = 0; y < numberOfCards; y++) {
if (currentHand.get(i).getRank() == currentHand.get(y).getRank()) {
counter++;
for (int x = 0; x < numberOfCards; x++) {
if (currentHand.get(i).getRank() == currentHand.get(x).getRank()) {
counter++;
}
}
if (counter == 3) {
return true;
} else {
return false;
}
}
private boolean isTwoPair() {
//check if it is four of a kind or two pair))
if (isFourOfAKind() == true) {
return false;
}
int numberOfPair = 0;
int counter = 1;
return false;
}
private boolean isOnePair() {
return false;
}
public boolean isRoyalPair() {
if (isOnePair() == false && isTwoPair() == false && isThreeOfAKind() == false && isFourOfAKind() == false
&& isFullHouse() == false && isRoyalFlush() == false && isFlush() == false && isStraight() == false && isStraightFlush() == false) {
return true;
}
return false;
}
private boolean isStraight(){
对于(int i=0;i
看起来好像没有调用checkHands()
等等
Collections.sort(sortedHand, new Comparator<Card>() {
@Override
public int compare(Card card1, Card card2) {
int rank1 = card1.getRank();
int rank2 = card2.getRank();
if (rank1 > rank2) {
return 1;
}
if (rank1 < rank2){
return -1;
}
return 0;
}
} /* Should be ); here */
int rank = 0;
...
手牌(一套5张牌)不应该有等级(至少如果你要拨打每张牌的号码,就不应该有等级)。手牌应该有一个名字,或者更确切地说是一个字符串,这是这些牌最好的牌。例如
String type = "none";
...
if (isRoyalFlush()) type = "Royal Flush!!!!!";
//or if(isRoyalFlush()) type = goodHandTypes[9];
注意,没有必要将它检查的内容与true
进行比较。有几种方法可以实现可读性和/或更少类型的逻辑
if (isRoyalPair() == true) {
rank = 1;
if (isTwoPair() == true) {
rank = 2;
}
...
String type = "none";
...
if (isRoyalFlush()) type = "Royal Flush!!!!!";
//or if(isRoyalFlush()) type = goodHandTypes[9];