Erasing stacks when empty. Also moved some event-related code to the keyboard object.
This commit is contained in:
parent
87909b5075
commit
7b39ec5cc6
@ -1,7 +1,5 @@
|
||||
#include <ncurses.h>
|
||||
#include <malloc.h>
|
||||
#include "stack.h"
|
||||
#include "deck.h"
|
||||
#include "display.h"
|
||||
#include "game.h"
|
||||
#include "cursor.h"
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define CURSOR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "deck.h"
|
||||
|
||||
#define CURSOR_STARTING_X 4
|
||||
#define CURSOR_STARTING_Y 7
|
||||
|
@ -46,6 +46,22 @@ char *card_value(enum value value) {
|
||||
return(card_value);
|
||||
}
|
||||
|
||||
void erase_stack(struct stack *stack) {
|
||||
WINDOW *empty_stack = NULL;
|
||||
|
||||
wbkgd(stack->card->frame->shape, WHITE_ON_GREEN);
|
||||
wrefresh(stack->card->frame->shape);
|
||||
empty_stack = newwin(FRAME_HEIGHT,
|
||||
FRAME_WIDTH,
|
||||
stack->card->frame->start_y,
|
||||
stack->card->frame->start_x);
|
||||
box(empty_stack, 0, 0);
|
||||
wrefresh(empty_stack);
|
||||
delwin(empty_stack);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void draw_empty_stacks() {
|
||||
WINDOW **empty_stack;
|
||||
|
||||
|
@ -13,9 +13,11 @@
|
||||
#define BLACK_ON_WHITE 1
|
||||
#define RED_ON_WHITE 2
|
||||
#define WHITE_ON_BLUE 3
|
||||
#define WHITE_ON_GREEN 4
|
||||
|
||||
char *card_suit(enum suit);
|
||||
char *card_value(enum value);
|
||||
void erase_stack(struct stack *);
|
||||
void draw_empty_stacks();
|
||||
void draw_value(struct card *);
|
||||
void draw_suit(struct card *);
|
||||
|
11
lib/game.c
11
lib/game.c
@ -220,14 +220,3 @@ void end_game(struct deck *deck) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void handle_stock_event() {
|
||||
if (!empty(deck->stock)) {
|
||||
move_card(&(deck->stock), &(deck->waste_pile));
|
||||
expose_card(deck->waste_pile->card);
|
||||
draw_stack(deck->stock);
|
||||
draw_stack(deck->waste_pile);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -36,6 +36,5 @@ void greet_player();
|
||||
void initialize_game();
|
||||
void prepare_game(struct deck **);
|
||||
void end_game();
|
||||
void handle_stock_event();
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include "display.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
void handle_stock_event() {
|
||||
if (!empty(deck->stock)) {
|
||||
/* erase the stack before emptying it */
|
||||
if (length(deck->stock) == 1) {
|
||||
erase_stack(deck->stock);
|
||||
}
|
||||
move_card(&(deck->stock), &(deck->waste_pile));
|
||||
expose_card(deck->waste_pile->card);
|
||||
draw_stack(deck->stock);
|
||||
draw_stack(deck->waste_pile);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int key_event() {
|
||||
int pressed_key;
|
||||
|
||||
|
@ -1,8 +1,13 @@
|
||||
#ifndef KEYBOARD_H
|
||||
#define KEYBOARD_H
|
||||
|
||||
#include "deck.h"
|
||||
|
||||
#define KEY_SPACEBAR ' '
|
||||
|
||||
extern struct deck *deck;
|
||||
|
||||
void handle_stock_event();
|
||||
int key_event();
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include "stack.h"
|
||||
#include "game.h"
|
||||
|
||||
void allocate_stack(struct stack **stack) {
|
||||
*stack = malloc(sizeof(**stack));
|
||||
@ -79,7 +80,12 @@ struct stack *pop(struct stack **stack) {
|
||||
}
|
||||
|
||||
bool maneuvre_stack(struct stack *stack) {
|
||||
return(stack->card->frame->start_y >= MANEUVRE_STACKS_START_Y);
|
||||
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) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "card.h"
|
||||
|
||||
#define MANEUVRE_STACKS_START_Y 7
|
||||
#define MANEUVRE_STACKS_STARTING_Y 7
|
||||
|
||||
struct stack {
|
||||
struct card *card;
|
||||
@ -18,6 +18,7 @@ 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 **);
|
||||
|
||||
|
@ -14,6 +14,7 @@ void initialize_curses() {
|
||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||
init_pair(2, COLOR_RED, COLOR_WHITE);
|
||||
init_pair(3, COLOR_WHITE, COLOR_BLUE);
|
||||
init_pair(4, COLOR_WHITE, COLOR_GREEN);
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user