Ver código fonte

Fixed roll-around. Added BONUS + redraws now.

Steve Thielemann 3 anos atrás
pai
commit
3fc220606c
3 arquivos alterados com 77 adições e 2 exclusões
  1. 63 0
      deck.cpp
  2. 12 2
      play.cpp
  3. 2 0
      play.h

+ 63 - 0
deck.cpp

@@ -320,6 +320,20 @@ bool Deck::can_play(int c1, int c2) {
 
 door::Panel *Deck::marker(int c) { return mark[c]; }
 
+/**
+ * @brief remove_card
+ *
+ * This removes a card at a given position (c).
+ * It needs to know if there are cards underneath
+ * to the left or right.  (If so, we restore those missing parts.)
+ *
+ * @param door
+ * @param c
+ * @param off_x
+ * @param off_y
+ * @param left
+ * @param right
+ */
 void Deck::remove_card(door::Door &door, int c, int off_x, int off_y, bool left,
                        bool right) {
   int cx, cy, level;
@@ -372,6 +386,19 @@ XXXXX   XXXXX   XXXXX
 
 width = 5 * 10 + (2 * 9) = 50+18 = 68   !  I could do that!
 */
+
+/**
+ * @brief Where does this card go in relation to everything else?
+ *
+ * This function is deprecated, see the other cardgo.
+ *
+ * @param pos
+ * @param space
+ * @param h
+ * @param x
+ * @param y
+ * @param level
+ */
 void cardgo(int pos, int space, int h, int &x, int &y, int &level) {
   // special cases here
   if (pos == 28) {
@@ -542,6 +569,14 @@ cards card_shuffle(std::seed_seq &seed, int decks) {
   return deck;
 }
 
+/**
+ * @brief generate a vector of ints to track card states.
+ *
+ * This initializes everything to 0.
+ *
+ * @param decks
+ * @return cards
+ */
 cards card_states(int decks) {
   // auto states = std::unique_ptr<std::vector<int>>(); // (decks * 52, 0)>;
   std::vector<int> states;
@@ -556,6 +591,9 @@ cards card_states(int decks) {
  * current is the current active card.
  * states is the card states (0 = down, 1 = in play, 2 = removed)
  *
+ * updated: If we can't go any further left (or right), then
+ * roll around to the other side.
+ *
  * @param left
  * @param states
  * @param current
@@ -569,6 +607,12 @@ int find_next(bool left, const cards &states, int current) {
   int x;
   int pos = -1;
   int pos_x;
+
+  int max_pos = -1;
+  int max_x = -1;
+  int min_pos = -1;
+  int min_x = 100;
+
   if (left)
     pos_x = 0;
   else
@@ -580,6 +624,15 @@ int find_next(bool left, const cards &states, int current) {
       if (x == current)
         continue;
       cardgo(x, cx, cy, level);
+      // find max and min while we're iterating here
+      if (cx < min_x) {
+        min_pos = x;
+        min_x = cx;
+      }
+      if (cx > max_x) {
+        max_pos = x;
+        max_x = cx;
+      }
       if (left) {
         if ((cx < current_x) and (cx > pos_x)) {
           pos_x = cx;
@@ -593,6 +646,16 @@ int find_next(bool left, const cards &states, int current) {
       }
     }
   }
+  if (pos == -1) {
+    // we couldn't find one
+    if (left) {
+      // use max -- roll around to the right
+      pos = max_pos;
+    } else {
+      // use min -- roll around to the left
+      pos = min_pos;
+    }
+  }
   return pos;
 }
 

+ 12 - 2
play.cpp

@@ -52,6 +52,10 @@ void PlayCards::init_values(void) {
   score = 0;
 }
 
+void PlayCards::bonus(void) {
+  door << door::ANSIColor(door::COLOR::YELLOW, door::ATTR::BOLD) << "BONUS";
+}
+
 int PlayCards::play_cards(void) {
   play_day = std::chrono::system_clock::now();
   init_values();
@@ -275,8 +279,9 @@ next_hand:
               // display something at active_card position
               int cx, cy, level;
               cardgo(active_card, cx, cy, level);
-              door << door::Goto(cx + off_x, cy + off_y) << door::reset
-                   << "BONUS";
+              door << door::Goto(cx + off_x, cy + off_y);
+              bonus();
+
               score += 100;
               state.at(active_card) = 3; // handle this in the "redraw"
             }
@@ -439,6 +444,11 @@ void PlayCards::redraw(bool dealing) {
       case 2:
         // no card to draw.  :)
         break;
+      case 3:
+        // peak cleared, draw bonus
+        door << door::Goto(cx + off_x, cy + off_y);
+        bonus();
+        break;
       }
     }
   }

+ 2 - 0
play.h

@@ -44,6 +44,7 @@ private:
   cards state;
 
   void redraw(bool dealing);
+  void bonus(void);
 
 public:
   PlayCards(door::Door &d, DBData &dbd, std::mt19937 &r);
@@ -51,6 +52,7 @@ public:
 
   int play_cards(void);
   void init_values(void);
+
   door::renderFunction statusValue(door::ANSIColor status,
                                    door::ANSIColor value);
   door::renderFunction commandLineRender(door::ANSIColor bracket,