Added function to fill the deck.
This commit is contained in:
parent
90c7ce6280
commit
b94341b70d
66
lib/deck.c
66
lib/deck.c
@ -61,3 +61,69 @@ void delete_deck(struct deck *deck) {
|
|||||||
|
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
|
|
||||||
|
#define NUMBER_OF_CARDS 52
|
||||||
|
|
||||||
struct deck {
|
struct deck {
|
||||||
struct stack *stock;
|
struct stack *stock;
|
||||||
|
|
||||||
@ -23,6 +25,6 @@ struct deck {
|
|||||||
void allocate_deck(struct deck **);
|
void allocate_deck(struct deck **);
|
||||||
void initialize_deck(struct deck *);
|
void initialize_deck(struct deck *);
|
||||||
void delete_deck(struct deck *);
|
void delete_deck(struct deck *);
|
||||||
void shuffle_deck(struct deck *);
|
void fill_deck(struct deck *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include "deck.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
void init_curses() {
|
void init_curses() {
|
||||||
@ -53,7 +54,7 @@ void initialize_game() {
|
|||||||
draw_empty_stacks();
|
draw_empty_stacks();
|
||||||
allocate_deck(&deck);
|
allocate_deck(&deck);
|
||||||
initialize_deck(deck);
|
initialize_deck(deck);
|
||||||
delete_deck(deck);
|
fill_deck(deck);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user