Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- /*
- GLOBAL VARIABLES
- */
- #define CARDS_NUM 13
- #define CARDS_IN_DECK 52
- typedef struct {
- int value;
- int representation;
- } card_t;
- typedef struct {
- card_t * cards;
- } deck_t;
- /*
- PRIMITIVES
- */
- void constructorDeckT(deck_t *);
- char * stringOfCard(card_t);
- int valueOfCard(card_t);
- void printDeck(deck_t);
- /*
- FUNCTIONS
- */
- int main(int argc, char*argv[]) {
- deck_t mazzo;
- constructorDeckT(&mazzo);
- printDeck(mazzo);
- }
- char * stringOfCard(card_t card) {
- switch (card.representation) {
- case 1:
- return "A\0";
- case 2:
- return "2\0";
- case 3:
- return "3\0";
- case 4:
- return "4\0";
- case 5:
- return "5\0";
- case 6:
- return "6\0";
- case 7:
- return "7\0";
- case 8:
- return "8\0";
- case 9:
- return "9\0";
- case 10:
- return "10\0";
- case 11:
- return "J\0";
- case 12:
- return "Q\0";
- case 13:
- return "K\0";
- default:
- return "?\0";
- }
- }
- int valueOfCard(card_t card) {
- if (card.representation > 0 && card.representation < 11)
- return card.representation;
- else
- return 10;
- }
- void constructorDeckT(deck_t * deck) {
- deck->cards = malloc(sizeof(CARDS_IN_DECK));
- int i, cardValue, cont;
- for (cardValue = 1, i = 0; i < CARDS_IN_DECK; cardValue++) {
- for(cont = 0; cont < 4; ) {
- deck->cards[i].representation = cardValue;
- deck->cards[i].value = valueOfCard(deck->cards[i]);
- cont++;
- i++;
- }
- cont = 0;
- }
- }
- void printDeck(deck_t deck) {
- int i;
- for (i = 0; i < CARDS_IN_DECK; i++) {
- printf("Card %d = %s\n", i+1, stringOfCard(deck.cards[i]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement