From b94341b70d34ab472018f0ffa2425fd2a6eebca4 Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Tue, 6 Apr 2010 22:52:00 -0300 Subject: [PATCH] Added function to fill the deck. --- lib/deck.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/deck.h | 4 +++- lib/display.c | 3 ++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/lib/deck.c b/lib/deck.c index 59361d3..b2337b3 100644 --- a/lib/deck.c +++ b/lib/deck.c @@ -61,3 +61,69 @@ void delete_deck(struct deck *deck) { return; } + +void fill_deck(struct deck *deck) { + struct card *card[NUMBER_OF_CARDS]; + + for (int i = 0; i < NUMBER_OF_CARDS; i++) { + allocate_card(&(card[i])); + } + set_card(card[0], TWO, DIAMONDS, COVERED, 1, 1); + set_card(card[1], TWO, SPADES, COVERED, 1, 1); + set_card(card[2], TWO, HEARTS, COVERED, 1, 1); + set_card(card[3], TWO, CLUBS, COVERED, 1, 1); + set_card(card[4], THREE, DIAMONDS, COVERED, 1, 1); + set_card(card[5], THREE, SPADES, COVERED, 1, 1); + set_card(card[6], THREE, HEARTS, COVERED, 1, 1); + set_card(card[7], THREE, CLUBS, COVERED, 1, 1); + set_card(card[8], FOUR, DIAMONDS, COVERED, 1, 1); + set_card(card[9], FOUR, SPADES, COVERED, 1, 1); + set_card(card[10], FOUR, HEARTS, COVERED, 1, 1); + set_card(card[11], FOUR, CLUBS, COVERED, 1, 1); + set_card(card[12], FIVE, DIAMONDS, COVERED, 1, 1); + set_card(card[13], FIVE, SPADES, COVERED, 1, 1); + set_card(card[14], FIVE, HEARTS, COVERED, 1, 1); + set_card(card[15], FIVE, CLUBS, COVERED, 1, 1); + set_card(card[16], SIX, DIAMONDS, COVERED, 1, 1); + set_card(card[17], SIX, SPADES, COVERED, 1, 1); + set_card(card[18], SIX, HEARTS, COVERED, 1, 1); + set_card(card[19], SIX, CLUBS, COVERED, 1, 1); + set_card(card[20], SEVEN, DIAMONDS, COVERED, 1, 1); + set_card(card[21], SEVEN, SPADES, COVERED, 1, 1); + set_card(card[22], SEVEN, HEARTS, COVERED, 1, 1); + set_card(card[23], SEVEN, CLUBS, COVERED, 1, 1); + set_card(card[24], EIGHT, DIAMONDS, COVERED, 1, 1); + set_card(card[25], EIGHT, SPADES, COVERED, 1, 1); + set_card(card[26], EIGHT, HEARTS, COVERED, 1, 1); + set_card(card[27], EIGHT, CLUBS, COVERED, 1, 1); + set_card(card[28], NINE, DIAMONDS, COVERED, 1, 1); + set_card(card[29], NINE, SPADES, COVERED, 1, 1); + set_card(card[30], NINE, HEARTS, COVERED, 1, 1); + set_card(card[31], NINE, CLUBS, COVERED, 1, 1); + set_card(card[32], TEN, DIAMONDS, COVERED, 1, 1); + set_card(card[33], TEN, SPADES, COVERED, 1, 1); + set_card(card[34], TEN, HEARTS, COVERED, 1, 1); + set_card(card[35], TEN, CLUBS, COVERED, 1, 1); + set_card(card[36], JACK, DIAMONDS, COVERED, 1, 1); + set_card(card[37], JACK, SPADES, COVERED, 1, 1); + set_card(card[38], JACK, HEARTS, COVERED, 1, 1); + set_card(card[39], JACK, CLUBS, COVERED, 1, 1); + set_card(card[40], QUEEN, DIAMONDS, COVERED, 1, 1); + set_card(card[41], QUEEN, SPADES, COVERED, 1, 1); + set_card(card[42], QUEEN, HEARTS, COVERED, 1, 1); + set_card(card[43], QUEEN, CLUBS, COVERED, 1, 1); + set_card(card[44], KING, DIAMONDS, COVERED, 1, 1); + set_card(card[45], KING, SPADES, COVERED, 1, 1); + set_card(card[46], KING, HEARTS, COVERED, 1, 1); + set_card(card[47], KING, CLUBS, COVERED, 1, 1); + set_card(card[48], ACE, DIAMONDS, COVERED, 1, 1); + set_card(card[49], ACE, SPADES, COVERED, 1, 1); + set_card(card[50], ACE, HEARTS, COVERED, 1, 1); + set_card(card[51], ACE, CLUBS, COVERED, 1, 1); + + for (int i = 0; i < NUMBER_OF_CARDS; i++) { + push(&(deck->stock), card[i]); + } + + return; +} diff --git a/lib/deck.h b/lib/deck.h index 6187440..c41e566 100644 --- a/lib/deck.h +++ b/lib/deck.h @@ -3,6 +3,8 @@ #include "stack.h" +#define NUMBER_OF_CARDS 52 + struct deck { struct stack *stock; @@ -23,6 +25,6 @@ struct deck { void allocate_deck(struct deck **); void initialize_deck(struct deck *); void delete_deck(struct deck *); -void shuffle_deck(struct deck *); +void fill_deck(struct deck *); #endif diff --git a/lib/display.c b/lib/display.c index b837aff..ed9cb2d 100644 --- a/lib/display.c +++ b/lib/display.c @@ -2,6 +2,7 @@ #include #include #include +#include "deck.h" #include "display.h" void init_curses() { @@ -53,7 +54,7 @@ void initialize_game() { draw_empty_stacks(); allocate_deck(&deck); initialize_deck(deck); - delete_deck(deck); + fill_deck(deck); return; }