Question
I am trying to create a deck of cards in drawPile when newGame is called (with specific cards given as parameters) I have 4 linked
I am trying to create a deck of cards in drawPile when newGame is called (with specific cards given as parameters)
I have 4 linked lists to store cards (drawPile,discardPile,player1's hand, and player2's hand)
My _game struct would store the state of my game at a given time (e.g. the cards in drawPile, discardPile, and player1,2's hands)
I am having trouble trying to understand how I should go about using drawPile linked list inside struct _game. How should I allocation memory for drawPile,discardPile..etc when _game is created? As I believe what I currently have in newGame is totally wrong.
below is the code:
typedef enum {RED,BLACK} color;
typedef enum {HEARTS,DIAMONDS,CLUBS,SPADES} suit; typedef enum {ONE,TWO,THREE,FOUR} value; typedef struct drawPile{ enum color color; enum suit suit; enum value value; struct drawPile *next; };
typedef struct discardPile{
enum color color; enum suit suit; enum value value; struct discardPile *next; }; typedef struct player1Hand{ enum color color; enum suit suit; enum value value; struct player1Hand *next; }; typedef struct player2Hand{ enum color color; enum suit suit; enum value value; struct player2Hand *next; }; typedef struct _game{ drawPile game_drawPile; discardPile game_discardPile; player1Hand game_player1Hand; player2Hand game_player2Hand; }Game; Game newGame(int deckSize, value values[], color colors[], suit suits[]){ Game nGame; for(int i = 0; i < deckSize; i++){ nGame->drawPile.value = value[i]; nGame->drawPile.color = colors[i]; nGame->drawPile.suit = suits[i]; } }
//below is an example main function of how the newGame function is going to run with only 4 cards.
int main (void){ init_deck(); } static void init_deck(void){ int deck_size = 4; value values[] = {ONE, TWO, THREE, FOUR}; color colors[] = {RED, BLACK, RED, BLACK}; suit suits[] = {HEARTS, DIAMONDS, CLUBS, SPADES}; Game game = newGame(deck_size, values, colors, suits); }
//I have only pasted segments of my code, please tell me if you need more information.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started