diff --git a/card.c b/card.c index 0f3bac4..2b22217 100644 --- a/card.c +++ b/card.c @@ -53,7 +53,7 @@ void remove_from_hand(Hand *h, Card *c) { h->count--; } -void add_to_hand(Hand *h, Card *c) { +int first_open_spot(Hand *h) { int order_guy[48]; int order_guy_count = 0; @@ -67,14 +67,17 @@ void add_to_hand(Hand *h, Card *c) { order_guy_count++; } - int first_open_spot = h->count; + int fos = h->count; for (int i = 0; i < order_guy_count; i++) { if (order_guy[i]) continue; - first_open_spot = i; + fos = i; break; } + return fos; +} - c->order = first_open_spot; +void add_to_hand(Hand *h, Card *c) { + c->order = first_open_spot(h); h->cards[h->count] = c; c->move.position = &c->position; @@ -82,19 +85,19 @@ void add_to_hand(Hand *h, Card *c) { c->move.origin.y = c->position.y; switch (h->display_type) { case HAND_DISPLAY_ROW: - c->move.destination.x = h->position.x + (first_open_spot * (CARD_WIDTH + 10)); + c->move.destination.x = h->position.x + (c->order * (CARD_WIDTH + 10)); c->move.destination.y = h->position.y; break; case HAND_DISPLAY_FIELD: - c->move.destination.x = h->position.x + ((first_open_spot / 2) * (CARD_WIDTH + 10)); - c->move.destination.y = h->position.y + (first_open_spot % 2 * (CARD_HEIGHT + 10)); + c->move.destination.x = h->position.x + ((c->order / 2) * (CARD_WIDTH + 10)); + c->move.destination.y = h->position.y + (c->order % 2 * (CARD_HEIGHT + 10)); break; case HAND_DISPLAY_DECK: c->move.destination.x = h->position.x; c->move.destination.y = h->position.y; break; case HAND_DISPLAY_SCORED: - c->move.destination.x = h->position.x + (first_open_spot * (CARD_WIDTH - 10)); + c->move.destination.x = h->position.x + (c->order * (CARD_WIDTH - 10)); c->move.destination.y = h->position.y; break; } @@ -119,9 +122,10 @@ void deal(Hand *from, Hand *to, int count, bool up) { } Rectangle next_card_position(Hand *h) { + int i = first_open_spot(h); return (Rectangle) { - h->position.x + ((h->count / 2) * (CARD_WIDTH + 10)), - h->position.y + (h->count % 2 * (CARD_HEIGHT + 10)), + h->position.x + ((i / 2) * (CARD_WIDTH + 10)), + h->position.y + (i % 2 * (CARD_HEIGHT + 10)), CARD_WIDTH, CARD_HEIGHT };