Declaring local functions as static.
This commit is contained in:
parent
83df7ba92f
commit
8d1b2ca7b4
@ -7,7 +7,7 @@
|
||||
#include "display.h"
|
||||
#include "game.h"
|
||||
|
||||
char *card_suit(enum suit suit) {
|
||||
static char *card_suit(enum suit suit) {
|
||||
char *card_suit;
|
||||
|
||||
if (!(card_suit = malloc(5 * sizeof(*card_suit)))) {
|
||||
@ -26,7 +26,7 @@ char *card_suit(enum suit suit) {
|
||||
return(card_suit);
|
||||
}
|
||||
|
||||
char *card_value(enum value value) {
|
||||
static char *card_value(enum value value) {
|
||||
char *card_value;
|
||||
|
||||
if (!(card_value = malloc(2 * sizeof(*card_value)))) {
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
extern const char *program_name;
|
||||
|
||||
char *card_suit(enum suit);
|
||||
char *card_value(enum value);
|
||||
void erase_stack(struct stack *);
|
||||
void draw_empty_stacks();
|
||||
void draw_value(struct card *);
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "game.h"
|
||||
#include "../debug/deck_debug.h" // noob debugging
|
||||
|
||||
void set_stacks_initial_coordinates(struct deck *deck) {
|
||||
static void set_stacks_initial_coordinates(struct deck *deck) {
|
||||
set_frame(deck->stock->card->frame,
|
||||
STOCK_STARTING_Y,
|
||||
STOCK_STARTING_X);
|
||||
@ -54,7 +54,7 @@ void set_stacks_initial_coordinates(struct deck *deck) {
|
||||
return;
|
||||
}
|
||||
|
||||
void fill_deck(struct deck *deck) {
|
||||
static void fill_deck(struct deck *deck) {
|
||||
struct card *card[NUMBER_OF_CARDS];
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_CARDS; i++) {
|
||||
@ -120,7 +120,7 @@ void fill_deck(struct deck *deck) {
|
||||
return;
|
||||
}
|
||||
|
||||
void shuffle_deck(struct deck *deck) {
|
||||
static void shuffle_deck(struct deck *deck) {
|
||||
struct stack **stack = NULL;
|
||||
struct stack tmp;
|
||||
int random;
|
||||
@ -150,7 +150,7 @@ void shuffle_deck(struct deck *deck) {
|
||||
return;
|
||||
}
|
||||
|
||||
void deal_cards(struct deck *deck) {
|
||||
static void deal_cards(struct deck *deck) {
|
||||
move_card(&(deck->stock), &(deck->maneuvre_0));
|
||||
expose_card(deck->maneuvre_0->card);
|
||||
move_card(&(deck->stock), &(deck->maneuvre_1));
|
||||
|
@ -10,10 +10,6 @@ extern const char *program_name;
|
||||
struct deck *deck;
|
||||
struct cursor *cursor;
|
||||
|
||||
void set_stacks_initial_coordinates(struct deck *);
|
||||
void fill_deck(struct deck *);
|
||||
void shuffle_deck(struct deck *);
|
||||
void deal_cards(struct deck *);
|
||||
void greet_player();
|
||||
void initialize_game();
|
||||
void end_game();
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "display.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
struct stack *cursor_stack(struct cursor *cursor) {
|
||||
static struct stack *cursor_stack(struct cursor *cursor) {
|
||||
struct stack *cursor_stack = NULL;
|
||||
|
||||
if (cursor->y == CURSOR_STARTING_Y) {
|
||||
@ -30,15 +30,16 @@ struct stack *cursor_stack(struct cursor *cursor) {
|
||||
return(cursor_stack);
|
||||
}
|
||||
|
||||
bool cursor_on_stack(struct cursor *cursor, struct stack *stack) {
|
||||
static bool cursor_on_stack(struct cursor *cursor, struct stack *stack) {
|
||||
return(cursor_stack(cursor) == stack);
|
||||
}
|
||||
|
||||
bool cursor_on_invalid_spot(struct cursor *cursor) {
|
||||
static bool cursor_on_invalid_spot(struct cursor *cursor) {
|
||||
return(cursor->x == CURSOR_INVALID_SPOT_X &&
|
||||
cursor->y == CURSOR_INVALID_SPOT_Y);
|
||||
}
|
||||
void handle_stock_event() {
|
||||
|
||||
static void handle_stock_event() {
|
||||
if (!empty(deck->stock)) {
|
||||
/* erase the stack before emptying it */
|
||||
if (length(deck->stock) == 1) {
|
||||
@ -53,7 +54,7 @@ void handle_stock_event() {
|
||||
return;
|
||||
}
|
||||
|
||||
void handle_card_movement(struct cursor *cursor) {
|
||||
static void handle_card_movement(struct cursor *cursor) {
|
||||
struct stack *origin = NULL;
|
||||
struct stack *destination = NULL;
|
||||
int option;
|
||||
|
@ -9,11 +9,6 @@
|
||||
extern struct deck *deck;
|
||||
extern struct cursor *cursor;
|
||||
|
||||
struct stack *cursor_stack(struct cursor *);
|
||||
bool cursor_on_stack(struct cursor *, struct stack *);
|
||||
bool cursor_on_invalid_spot(struct cursor *);
|
||||
void handle_stock_event();
|
||||
void handle_card_movement(struct cursor *);
|
||||
void handle_keyboard_event();
|
||||
|
||||
#endif
|
||||
|
38
lib/stack.c
38
lib/stack.c
@ -6,6 +6,25 @@
|
||||
#include <errno.h>
|
||||
#include "stack.h"
|
||||
|
||||
static bool maneuvre_stack(struct stack *stack) {
|
||||
return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y);
|
||||
}
|
||||
|
||||
static bool waste_pile_stack(struct stack *stack) {
|
||||
return((stack->card->frame->start_x == WASTE_PILE_STARTING_X) &&
|
||||
(stack->card->frame->start_y == WASTE_PILE_STARTING_Y));
|
||||
}
|
||||
|
||||
static 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 allocate_stack(struct stack **stack) {
|
||||
if (!(*stack = malloc(sizeof(**stack)))) {
|
||||
fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
|
||||
@ -85,25 +104,6 @@ struct stack *pop(struct stack **stack) {
|
||||
return(popped_entry);
|
||||
}
|
||||
|
||||
bool maneuvre_stack(struct stack *stack) {
|
||||
return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y);
|
||||
}
|
||||
|
||||
bool waste_pile_stack(struct stack *stack) {
|
||||
return((stack->card->frame->start_x == WASTE_PILE_STARTING_X) &&
|
||||
(stack->card->frame->start_y == WASTE_PILE_STARTING_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;
|
||||
|
||||
|
@ -40,9 +40,6 @@ bool empty(struct stack *);
|
||||
int length(struct stack *);
|
||||
void push(struct stack **, struct card *);
|
||||
struct stack *pop(struct stack **);
|
||||
bool maneuvre_stack(struct stack *);
|
||||
bool waste_pile_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