deck.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef DECK_H
  2. #define DECK_H
  3. #include "door.h"
  4. #include <memory>
  5. #include <random>
  6. #include <string>
  7. #include <utility> // pair
  8. #include <vector>
  9. /*
  10. https://en.wikipedia.org/wiki/Code_page_437
  11. using: \xb0, 0xb1, 0xb2, 0xdb
  12. OR: \u2591, \u2592, \u2593, \u2588
  13. Like so:
  14. ##### #####
  15. ##### #####
  16. ##### #####
  17. Cards: (Black on White, or Red on White)
  18. 8D### TH###
  19. ##D## ##H##
  20. ###D8 ###HT
  21. D, H = Red, Clubs, Spades = Black.
  22. ^ Where D = Diamonds, H = Hearts
  23. ♥, ♦, ♣, ♠
  24. \x03, \x04, \x05, \x06
  25. \u2665, \u2666, \u2663, \u2660
  26. I tried card_height = 5, but the cards looked a little too stretched out/tall.
  27. 3 looks good.
  28. layout, rev2:
  29. 12345678901234567890123456789012345678901234567890123456789012345678901234567890
  30. +---------------------------------+
  31. Space Ace - Tri-Peaks Solitaire
  32. +---------------------------------+
  33. Cards start at 0, not 1!
  34. ░░1░░ ░░2░░ ░░3░░
  35. ░░░░░ ░░░░░ ░░░░░
  36. ▒▒4▒▒░░░▒▒5▒▒ ##6##░░░##7## ##8##░░░##9##
  37. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  38. ▓▓10▓▒▒▒▓▓11▓▒▒▒▓▓12▓ ##13#===##14#===##15# ##16#===##17#===##18#
  39. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  40. ██19█▓▓▓██20█▓▓▓██21█▓▓▓##22#===##23#===##24#===##25#===##26#===##27#===##28#
  41. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  42. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  43. Name: ##30# --29- Playing: December 31
  44. Score: ##### ----- Current Streak: nn
  45. Time used: xxx / XXX left ##### ----- Longest Streak: nn
  46. Playing Hand X of X Cards left XX
  47. 1234567890123456789012345 123456789012345 12345678901234567890
  48. [4/<] Left [6/>] Right [Space] Play Card [Enter] Draw [Q]uit [R]edraw [H]elp
  49. ^ -- above is 20 lines from +-- to [4/<] < Left
  50. score_panel left_panel streak_panel
  51. command_panel
  52. #####
  53. Player Information ##### Time in: xx Time out: xx
  54. Name: ##### Playing Day: November 3rd
  55. Hand Score : Current Streak: N
  56. Todays Score : XX Cards Remaining Longest Streak: NN
  57. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  58. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  59. layout, rev1:
  60. ░░░░░ ░░░░░ ░░░░░
  61. ░░░░░ ░░░░░ ░░░░░
  62. ▒▒▒▒▒░▒▒▒▒▒ #####░##### #####░#####
  63. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  64. ▓▓▓▓▓▒▓▓▓▓▓▒▓▓▓▓▓ #####=#####=##### #####=#####=#####
  65. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  66. █████▓█████▓█████▓#####=#####=#####=#####=#####=#####=#####
  67. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  68. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  69. #####
  70. Player Information ##### Time in: xx Time out: xx
  71. Name: ##### Playing Day: November 3rd
  72. Hand Score : Current Streak: N
  73. Todays Score : XX Cards Remaining Longest Streak: NN
  74. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  75. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  76. Spacing 1 or 3. 1 is what was used before, 3 looks better, takes up more
  77. screenspace. And I have plenty, even on 80x23.
  78. TODO: Have functions that gives me:
  79. int deck(int c); // which deck #
  80. int suit(int c); // suit
  81. int rank(int c); // rank
  82. */
  83. typedef std::vector<int> cards; // or a "deck"
  84. typedef std::shared_ptr<door::Panel> shared_panel;
  85. class Deck {
  86. private:
  87. // We assume for this game that there's only one deck back color.
  88. door::ANSIColor card_back_color;
  89. vector<shared_panel> cards;
  90. vector<shared_panel> backs;
  91. vector<shared_panel> mark;
  92. shared_panel cardOf(int c);
  93. std::string backSymbol(int level);
  94. shared_panel backOf(int level);
  95. shared_panel markOf(int c);
  96. char rankSymbol(int c);
  97. std::string suitSymbol(int c);
  98. const int card_height = 3;
  99. public:
  100. enum SUIT { HEART, DIAMOND, CLUBS, SPADE };
  101. const static std::array<std::pair<int, int>, 18> blocks;
  102. Deck(door::ANSIColor backcolor = door::ANSIColor(door::COLOR::RED));
  103. Deck(Deck &&);
  104. Deck &operator=(Deck &&);
  105. ~Deck();
  106. void setBack(door::ANSIColor backcolor);
  107. int getRank(int c);
  108. int getSuit(int c);
  109. int getDeck(int c);
  110. bool canPlay(int card1, int card2);
  111. shared_panel card(int c);
  112. shared_panel back(int level);
  113. shared_panel marker(int c);
  114. std::vector<int> unblocks(int card);
  115. void removeCard(door::Door &door, int c, int off_x, int off_y, bool left,
  116. bool right);
  117. };
  118. void cardPos(int pos, int &x, int &y);
  119. void cardLevel(int pos, int &level);
  120. void cardPosLevel(int pos, int &x, int &y, int &level);
  121. cards shuffleCards(std::seed_seq &seed, int decks = 1);
  122. cards makeCardStates(int decks = 1);
  123. int findNextActiveCard(bool left, const cards &states, int current);
  124. int findClosestActiveCard(const cards &states, int current);
  125. extern vector<std::string> deck_colors;
  126. door::renderFunction makeColorRender(door::ANSIColor c1, door::ANSIColor c2,
  127. door::ANSIColor c3);
  128. door::ANSIColor stringToANSIColor(std::string colorCode);
  129. std::string stringFromColorOptions(int opt);
  130. door::Panel make_about(void);
  131. door::Panel make_help(void);
  132. void display_starfield(door::Door &door, std::mt19937 &rng);
  133. void display_space_ace(door::Door &door);
  134. void display_starfield_space_ace(door::Door &door, std::mt19937 &rng);
  135. door::Panel make_timeout(int mx, int my);
  136. door::Panel make_notime(int mx, int my);
  137. door::Menu make_main_menu(void);
  138. door::Menu make_config_menu(void);
  139. door::Menu make_deck_menu(void);
  140. door::Panel make_sysop_config(void);
  141. #endif