Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #define COLOR_SIZE 5
  4.  
  5. //visual studio compatibility
  6. #ifdef _MSC_VER
  7. #define _CRT_SECURE_NO_DEPRECATE
  8. #pragma warning (disable : 4996)
  9. #endif
  10.  
  11. //struktura talii jako lista
  12. typedef struct deck {
  13. int card_value;
  14. char znak[6];
  15. struct deck* next;
  16. }deck_t;
  17.  
  18. //znaki do inicjalizacji w funkcjach
  19. char pik[4] = "PIK";
  20. char kier[5] = "KIER";
  21. char trefl[6] = "TREFL";
  22. char karo[5] = "KARO";
  23.  
  24. //inicjalizacja talii kart
  25. void init_deck(deck_t *deck)
  26. {
  27. deck->next = NULL;
  28. }
  29.  
  30. //wypelnienie talii kart
  31. void create_deck(deck_t* deck,int value,int znak)
  32. {
  33. deck_t* x = (deck_t*)malloc(sizeof(deck_t));
  34.  
  35. x->card_value = value;
  36. if (znak == 0)
  37. {
  38. strncpy (x->znak, pik , 4);
  39. x->znak[3] = '\0';
  40. }
  41. else if (znak == 1)
  42. {
  43. strncpy(x->znak, kier, 5);
  44. x->znak[4] = '\0';
  45. }
  46. else if (znak == 2)
  47. {
  48. strncpy(x->znak, trefl, 6);
  49. x->znak[5] = '\0';
  50. }
  51. else if (znak == 3)
  52. {
  53. strncpy(x->znak, karo, 5);
  54. x->znak[4] = '\0';
  55. }
  56. x->next = deck->next;
  57. deck->next = x;
  58. }
  59.  
  60. //losowanie rÄ…k graczy
  61. void create_hand(deck_t*hand_x,deck_t*hand_y,deck_t*deck)
  62. {
  63.  
  64. }
  65.  
  66.  
  67.  
  68. /*void print(deck_t* deck)
  69. {
  70. deck = deck->next;
  71. while (deck != NULL)
  72. {
  73. std::cout << deck->card_value << " " << deck->znak << std::endl;
  74. deck = deck->next;
  75. }
  76. }*/
  77.  
  78.  
  79.  
  80.  
  81.  
  82. int main()
  83. {
  84. deck_t deck[COLOR_SIZE * 4];
  85.  
  86. deck_t* cur = &deck;
  87. for (int j = 0; j < 4; j++)
  88. {
  89. for (int i = 14; i > 14 - COLOR_SIZE; i--)
  90. {
  91. create_deck(cur, i, j);
  92. cur = cur->next;
  93. }
  94. }
  95.  
  96. deck_t* hand_x = (deck_t*)malloc(sizeof(deck_t));
  97. deck_t* hand_y = (deck_t*)malloc(sizeof(deck_t));
  98. if (hand_x == NULL||hand_y==NULL)
  99. std::cout << "Blad przy alokacji pamieci!" << std::endl;
  100. else
  101. {
  102. std::cout << cur->card_value;
  103. }
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement