c1和c2來自我的卡對象,並且p。東西來自我的玩家類。我正試圖交換牌,以便牌從最小到最大。牌被處理,他們只是不正確。如果你需要我參加我的球員課程和卡班,我將非常樂意。任何幫助,將不勝感激。我需要幫助排列撲克牌
public static void SortCards(Player p)
{
Card c1 = null;
Card c2 = null;
int a = 0;
int b = 0;
int c = 0;
int temp = 0;
int card1 = 0;
int card2 = 0;
String p1;
// pull out player
// get card
// set at positions
// loop goes to the size of the hand
for (a = 0; a < p.handSize(); a++)
{
c = a;
b = a + 1;
for (b = 0; b < p.handSize(); b++)
{
c1 = p.Hand.get(b);
c2 = p.Hand.get(c);
card1 = c1.getValue();
card2 = c2.getValue();
if (card1 < card2)
{
c = b;
}
b = b + 1;
}
p.Hand.setElementAt(c2, card1);
p.Hand.setElementAt(c1, card2);
}
}
考慮實現可比性(或寫一個比較器),只是使用排序。 – 2012-01-10 21:42:58