From a7bcc8e5a78ae2297fe096c4551194f3959d18ca Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Mon, 19 Apr 2010 21:58:31 -0300 Subject: [PATCH] Making room for cursor, DRY'ing up code. --- lib/display.c | 65 ++++++++++++++++++++++++++++++++++++++++----------- lib/game.c | 22 ++++++++--------- lib/game.h | 16 ++++--------- 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/lib/display.c b/lib/display.c index fd74ea8..9befe79 100644 --- a/lib/display.c +++ b/lib/display.c @@ -50,19 +50,58 @@ void draw_empty_stacks() { empty_stack = malloc(EMPTY_STACKS_NUMBER * sizeof(**empty_stack)); - empty_stack[0] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 1); - empty_stack[1] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 9); - empty_stack[2] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 25); - empty_stack[3] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 33); - empty_stack[4] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 41); - empty_stack[5] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 1, 49); - empty_stack[6] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 1); - empty_stack[7] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 9); - empty_stack[8] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 17); - empty_stack[9] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 25); - empty_stack[10] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 33); - empty_stack[11] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 41); - empty_stack[12] = newwin(FRAME_HEIGHT, FRAME_WIDTH, 7, 49); + empty_stack[0] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + STOCK_STARTING_Y, + STOCK_STARTING_X); + empty_stack[1] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + WASTE_PILE_STARTING_Y, + WASTE_PILE_STARTING_X); + empty_stack[2] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + FOUNDATION_STARTING_Y, + FOUNDATION_0_STARTING_X); + empty_stack[3] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + FOUNDATION_STARTING_Y, + FOUNDATION_1_STARTING_X); + empty_stack[4] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + FOUNDATION_STARTING_Y, + FOUNDATION_2_STARTING_X); + empty_stack[5] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + FOUNDATION_STARTING_Y, + FOUNDATION_3_STARTING_X); + empty_stack[6] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_0_STARTING_X); + empty_stack[7] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_1_STARTING_X); + empty_stack[8] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_2_STARTING_X); + empty_stack[9] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_3_STARTING_X); + empty_stack[10] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_4_STARTING_X); + empty_stack[11] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_5_STARTING_X); + empty_stack[12] = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + MANEUVRE_STARTING_Y, + MANEUVRE_6_STARTING_X); for (int i = 0; i < EMPTY_STACKS_NUMBER; i++) { box(empty_stack[i], 0, 0); diff --git a/lib/game.c b/lib/game.c index 9a36e17..f4ad7fe 100644 --- a/lib/game.c +++ b/lib/game.c @@ -13,37 +13,37 @@ void set_stacks_coordinates(struct deck *deck) { WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X); set_frame(deck->foundation_0->card->frame, - FOUNDATION_0_STARTING_Y, + FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X); set_frame(deck->foundation_1->card->frame, - FOUNDATION_1_STARTING_Y, + FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X); set_frame(deck->foundation_2->card->frame, - FOUNDATION_2_STARTING_Y, + FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X); set_frame(deck->foundation_3->card->frame, - FOUNDATION_3_STARTING_Y, + FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X); set_frame(deck->maneuvre_0->card->frame, - MANEUVRE_0_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X); set_frame(deck->maneuvre_1->card->frame, - MANEUVRE_1_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X); set_frame(deck->maneuvre_2->card->frame, - MANEUVRE_2_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X); set_frame(deck->maneuvre_3->card->frame, - MANEUVRE_3_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X); set_frame(deck->maneuvre_4->card->frame, - MANEUVRE_4_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X); set_frame(deck->maneuvre_5->card->frame, - MANEUVRE_5_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X); set_frame(deck->maneuvre_6->card->frame, - MANEUVRE_6_STARTING_Y, + MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X); return; diff --git a/lib/game.h b/lib/game.h index 241ae0f..9359d51 100644 --- a/lib/game.h +++ b/lib/game.h @@ -7,30 +7,24 @@ #define STOCK_STARTING_X 1 #define STOCK_STARTING_Y 1 + #define WASTE_PILE_STARTING_X 9 #define WASTE_PILE_STARTING_Y 1 + +#define FOUNDATION_STARTING_Y 1 #define FOUNDATION_0_STARTING_X 25 -#define FOUNDATION_0_STARTING_Y 1 #define FOUNDATION_1_STARTING_X 33 -#define FOUNDATION_1_STARTING_Y 1 #define FOUNDATION_2_STARTING_X 41 -#define FOUNDATION_2_STARTING_Y 1 #define FOUNDATION_3_STARTING_X 49 -#define FOUNDATION_3_STARTING_Y 1 + +#define MANEUVRE_STARTING_Y 9 #define MANEUVRE_0_STARTING_X 1 -#define MANEUVRE_0_STARTING_Y 7 #define MANEUVRE_1_STARTING_X 9 -#define MANEUVRE_1_STARTING_Y 7 #define MANEUVRE_2_STARTING_X 17 -#define MANEUVRE_2_STARTING_Y 7 #define MANEUVRE_3_STARTING_X 25 -#define MANEUVRE_3_STARTING_Y 7 #define MANEUVRE_4_STARTING_X 33 -#define MANEUVRE_4_STARTING_Y 7 #define MANEUVRE_5_STARTING_X 41 -#define MANEUVRE_5_STARTING_Y 7 #define MANEUVRE_6_STARTING_X 49 -#define MANEUVRE_6_STARTING_Y 7 void set_stacks_coordinates(struct deck *); void fill_deck(struct deck *);