deck.h 5.9 KB

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