Moving game logic to the game object.

This commit is contained in:
Murilo Pereira
2011-02-16 22:26:18 -02:00
parent 3495e08490
commit b1000cfb55
6 changed files with 140 additions and 142 deletions

View File

@@ -9,6 +9,25 @@
#include "util.h"
#include "game.h"
static bool maneuvre_stack(struct stack *stack) {
return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y);
}
void move_card(struct stack **origin, struct stack **destination) {
struct stack *stack = NULL;
(*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++;
}
if ((stack = pop(origin))) {
push(destination, stack->card);
}
return;
}
static void set_stacks_initial_coordinates(struct deck *deck) {
set_frame(deck->stock->card->frame,
STOCK_STARTING_Y,

View File

@@ -10,6 +10,7 @@ extern const char *program_name;
struct deck *deck;
struct cursor *cursor;
void move_card(struct stack **, struct stack **);
void greet_player();
void initialize_game();
void end_game();

View File

@@ -6,10 +6,6 @@
#include <errno.h>
#include "stack.h"
static bool maneuvre_stack(struct stack *stack) {
return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y);
}
void allocate_stack(struct stack **stack) {
if (!(*stack = malloc(sizeof(**stack)))) {
fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
@@ -100,18 +96,3 @@ struct stack *pop(struct stack **stack) {
return(popped_entry);
}
void move_card(struct stack **origin, struct stack **destination) {
struct stack *stack = NULL;
(*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++;
}
if ((stack = pop(origin))) {
push(destination, stack->card);
}
return;
}

View File

@@ -40,6 +40,5 @@ bool empty(struct stack *);
int length(struct stack *);
void push(struct stack **, struct card *);
struct stack *pop(struct stack **);
void move_card(struct stack **, struct stack **);
#endif