When a card is moved between stacks, its coordinates are refreshed.
This commit is contained in:
parent
65a8b5e0e3
commit
0c798f3d56
21
lib/stack.c
21
lib/stack.c
@ -56,15 +56,19 @@ void push(struct stack **stack, struct card *card) {
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: uglyness inside if statement */
|
||||
/* FIXME: hack hack hack to get the old coordinates after clearing the structure */
|
||||
struct stack *pop(struct stack **stack) {
|
||||
struct stack *popped_entry = NULL;
|
||||
|
||||
if(!empty(*stack)) {
|
||||
popped_entry = *stack;
|
||||
if (length(*stack) == 1) {
|
||||
int start_y, start_x;
|
||||
start_y = (*stack)->card->frame->start_y;
|
||||
start_x = (*stack)->card->frame->start_x;
|
||||
allocate_stack(stack);
|
||||
initialize_stack(*stack);
|
||||
set_frame((*stack)->card->frame, start_y, start_x);
|
||||
} else {
|
||||
*stack = (*stack)->next;
|
||||
}
|
||||
@ -74,9 +78,24 @@ struct stack *pop(struct stack **stack) {
|
||||
return(popped_entry);
|
||||
}
|
||||
|
||||
bool maneuvre_stack(struct stack *stack) {
|
||||
return(stack->card->frame->start_y == MANEUVRE_STACKS_START_Y);
|
||||
}
|
||||
|
||||
void refresh_card_coordinates(struct stack *origin, struct stack *destination) {
|
||||
origin->card->frame->start_x = destination->card->frame->start_x;
|
||||
origin->card->frame->start_y = destination->card->frame->start_y;
|
||||
if (!empty(destination) && maneuvre_stack(destination)) {
|
||||
origin->card->frame->start_y++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void move_card(struct stack **origin, struct stack **destination) {
|
||||
struct stack *stack = NULL;
|
||||
|
||||
refresh_card_coordinates(*origin, *destination);
|
||||
stack = pop(origin);
|
||||
push(destination, stack->card);
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "card.h"
|
||||
|
||||
#define MANEUVRE_STACKS_START_Y 7
|
||||
|
||||
struct stack {
|
||||
struct card *card;
|
||||
struct stack *next;
|
||||
@ -15,6 +17,8 @@ bool empty(struct stack *);
|
||||
int length(struct stack *);
|
||||
void push(struct stack **, struct card *);
|
||||
struct stack *pop(struct stack **);
|
||||
bool maneuvre_stack(struct stack *);
|
||||
void refresh_card_coordinates(struct stack *, struct stack *);
|
||||
void move_card(struct stack **, struct stack **);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user