Modularization started.
This commit is contained in:
44
lib/card.c
Normal file
44
lib/card.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <ncurses.h>
|
||||
#include <malloc.h>
|
||||
#include "card.h"
|
||||
#include "frame.h"
|
||||
#include "../src/common.h"
|
||||
|
||||
struct card *initialize_card() {
|
||||
struct card *card = NULL;
|
||||
|
||||
card = malloc(sizeof(card));
|
||||
|
||||
card->frame = initialize_frame();
|
||||
card->value = NONE;
|
||||
card->suit = NONE;
|
||||
card->exposed = FALSE;
|
||||
|
||||
return(card);
|
||||
}
|
||||
|
||||
void delete_card(struct card *card) {
|
||||
delete_frame(card->frame);
|
||||
free(card);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void set_card(struct card *card,
|
||||
enum value value,
|
||||
enum suit suit,
|
||||
char exposed,
|
||||
int start_y,
|
||||
int start_x) {
|
||||
set_frame(card->frame, start_y, start_x);
|
||||
card->value = value;
|
||||
card->suit = suit;
|
||||
card->exposed = exposed;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void refresh_card(struct card *card) {
|
||||
box(card->frame->shape, 0, 0);
|
||||
wrefresh(card->frame->shape);
|
||||
}
|
||||
41
lib/card.h
Normal file
41
lib/card.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef CARD_H
|
||||
#define CARD_H
|
||||
|
||||
enum suit {
|
||||
BLANK = -1,
|
||||
DIAMONDS = 0,
|
||||
SPADES = 1,
|
||||
HEARTS = 2,
|
||||
CLUBS = 3
|
||||
};
|
||||
|
||||
enum value {
|
||||
NONE = -1,
|
||||
TWO = 2,
|
||||
THREE = 3,
|
||||
FOUR = 4,
|
||||
FIVE = 5,
|
||||
SIX = 6,
|
||||
SEVEN = 7,
|
||||
EIGHT = 8,
|
||||
NINE = 9,
|
||||
TEN = 10,
|
||||
JACK = 11,
|
||||
QUEEN = 12,
|
||||
KING = 13,
|
||||
ACE = 14
|
||||
};
|
||||
|
||||
struct card {
|
||||
struct frame *frame;
|
||||
enum value value;
|
||||
enum suit suit;
|
||||
char exposed;
|
||||
};
|
||||
|
||||
struct card *initialize_card();
|
||||
void delete_card(struct card *);
|
||||
void set_card(struct card *, enum value, enum suit, char, int, int);
|
||||
void refresh_card(struct card *);
|
||||
|
||||
#endif
|
||||
43
lib/frame.c
Normal file
43
lib/frame.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <ncurses.h>
|
||||
#include <malloc.h>
|
||||
#include "frame.h"
|
||||
|
||||
WINDOW *initialize_shape() {
|
||||
WINDOW *shape;
|
||||
|
||||
shape = malloc(sizeof(shape));
|
||||
|
||||
return(shape);
|
||||
}
|
||||
|
||||
struct frame *initialize_frame() {
|
||||
struct frame *frame = NULL;
|
||||
|
||||
frame = malloc(sizeof(frame));
|
||||
|
||||
frame->shape = initialize_shape();
|
||||
frame->height = FRAME_HEIGHT;
|
||||
frame->width = FRAME_WIDTH;
|
||||
frame->start_y = 0;
|
||||
frame->start_x = 0;
|
||||
|
||||
return(frame);
|
||||
}
|
||||
|
||||
void delete_frame(struct frame *frame) {
|
||||
free(frame->shape);
|
||||
free(frame);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void set_frame(struct frame *frame, int start_y, int start_x) {
|
||||
frame->start_y = start_y;
|
||||
frame->start_x = start_x;
|
||||
frame->shape = newwin(frame->height,
|
||||
frame->width,
|
||||
frame->start_y,
|
||||
frame->start_x);
|
||||
|
||||
return;
|
||||
}
|
||||
20
lib/frame.h
Normal file
20
lib/frame.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef FRAME_H
|
||||
#define FRAME_H
|
||||
|
||||
#define FRAME_WIDTH 7
|
||||
#define FRAME_HEIGHT 5
|
||||
|
||||
struct frame {
|
||||
WINDOW *shape;
|
||||
int height;
|
||||
int width;
|
||||
int start_y;
|
||||
int start_x;
|
||||
};
|
||||
|
||||
WINDOW *initialize_shape();
|
||||
struct frame *initialize_frame();
|
||||
void delete_frame(struct frame *);
|
||||
void set_frame(struct frame *, int, int);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user