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