我的头不再工作了。我必须尽快完成这个我怎样才能让这个 for 循环更短。
目前我有 4 个不同的 for 循环。我想把它们结合起来,只有一个。
Card[] cards = new Card[4*13];
void testCreateCards() {
int k = 0;
for (int suit = 0; suit <= 3; suit++) { // for suit
for (int value = 1; value <= 13; value++) { // from Ace to King
// build new card
cards[k++] = new Card(suit, value);
}
}
}
void testDrawClubs() {
int x = 0;
int y = 0;
for (int i = 0; i <= 12; i++) {
cards[i].displayCard(x, y);
x +=80;
}
}
void testDrawDiamonds() {
int x = 0;
int y = 80;
for (int i = 13; i <= 25; i++) {
cards[i].displayCard(x, y);
x +=80;
}
}
void testDrawHearts() {
int x = 0;
int y = 160;
for (int i = 26; i <= 38; i++) {
cards[i].displayCard(x, y);
x +=80;
}
}
void testDrawSpades() {
int x = 0;
int y = 240;
for (int i = 39; i <= 51; i++) {
cards[i].displayCard(x, y);
x +=80;
}
}