我有問題,我滿屋子的方法。我認爲這很簡單,就像檢查一種和一對三種一樣簡單。但是用我目前的代碼,我只有三種房產。代碼isFullHouse()isThreeOfAKind()和isPair()在下面,謝謝所有的幫助!爲什麼我的isFullHouse()方法也接受一個簡單的三類?
public boolean isPair() {
Pips[] values = new Pips[5];
int count =0;
//Put each cards numeric value into array
for(int i = 0; i < cards.length; i++){
values[i] = cards[i].getPip();
}
//Loop through the values. Compare each value to all values
//If exactly two matches are made - return true
for(int x = 1; x < values.length; x++){
for(int y = 0; y < x; y++){
if(values[x].equals(values[y])) count++;
}
if (count == 1) return true;
count = 0;
}
return false;
}
public boolean isThreeOfAKind() {
Pips[] values = new Pips[5];
int counter = 0;
for(int i = 0; i < cards.length; i++){
values[i] = cards[i].getPip();
}
//Same process as isPair(), except return true for 3 matches
for(int x = 2; x < values.length; x++){
for(int y = 0; y < x; y++){
if(values[x].equals(values[y]))
counter++;
}
if(counter == 2) return true;
counter = 0;
}
return false;
}
public boolean isFullHouse(){
if(isThreeOfAKind() && isPair())
return true;
return false;
}
哈哈一堆撲克玩家在這裏! – 2010-10-05 02:23:48