solitaire_10.py Diff

solitaire_10.py
--- C:\Users\craven\Desktop\WebServer\arcade\doc\tutorials\card_game\solitaire_09.py
+++ C:\Users\craven\Desktop\WebServer\arcade\doc\tutorials\card_game\solitaire_10.py
@@ -47,6 +47,9 @@
 
 # If we fan out cards stacked on each other, how far apart to fan them?
 CARD_VERTICAL_OFFSET = CARD_HEIGHT * CARD_SCALE * 0.3
+
+# Face down image
+FACE_DOWN_IMAGE = ":resources:images/cards/cardBack_red2.png"
 
 # Constants that represent "what pile is what" for the game
 PILE_COUNT = 13
@@ -77,9 +80,24 @@
 
         # Image to use for the sprite when face up
         self.image_file_name = f":resources:images/cards/card{self.suit}{self.value}.png"
-
-        # Call the parent
-        super().__init__(self.image_file_name, scale, calculate_hit_box=False)
+        self.is_face_up = False
+        super().__init__(FACE_DOWN_IMAGE, scale, calculate_hit_box=False)
+
+    def face_down(self):
+        """ Turn card face-down """
+        self.texture = arcade.load_texture(FACE_DOWN_IMAGE)
+        self.is_face_up = False
+
+    def face_up(self):
+        """ Turn card face-up """
+        self.texture = arcade.load_texture(self.image_file_name)
+        self.is_face_up = True
+
+    @property
+    def is_face_down(self):
+        """ Is this card face down? """
+        return not self.is_face_up
+
 
 class MyGame(arcade.Window):
     """ Main application class. """
@@ -179,6 +197,10 @@
                 # Put on top in draw order
                 self.pull_to_top(card)
 
+        # Flip up the top cards
+        for i in range(PLAY_PILE_1, PLAY_PILE_7 + 1):
+            self.piles[i][-1].face_up()
+
     def on_draw(self):
         """ Render the screen. """
         # Clear the screen
@@ -214,20 +236,24 @@
             # Figure out what pile the card is in
             pile_index = self.get_pile_for_card(primary_card)
 
-            # All other cases, grab the face-up card we are clicking on
-            self.held_cards = [primary_card]
-            # Save the position
-            self.held_cards_original_position = [self.held_cards[0].position]
-            # Put on top in drawing order
-            self.pull_to_top(self.held_cards[0])
-
-            # Is this a stack of cards? If so, grab the other cards too
-            card_index = self.piles[pile_index].index(primary_card)
-            for i in range(card_index + 1, len(self.piles[pile_index])):
-                card = self.piles[pile_index][i]
-                self.held_cards.append(card)
-                self.held_cards_original_position.append(card.position)
-                self.pull_to_top(card)
+            if primary_card.is_face_down:
+                # Is the card face down? In one of those middle 7 piles? Then flip up
+                primary_card.face_up()
+            else:
+                # All other cases, grab the face-up card we are clicking on
+                self.held_cards = [primary_card]
+                # Save the position
+                self.held_cards_original_position = [self.held_cards[0].position]
+                # Put on top in drawing order
+                self.pull_to_top(self.held_cards[0])
+
+                # Is this a stack of cards? If so, grab the other cards too
+                card_index = self.piles[pile_index].index(primary_card)
+                for i in range(card_index + 1, len(self.piles[pile_index])):
+                    card = self.piles[pile_index][i]
+                    self.held_cards.append(card)
+                    self.held_cards_original_position.append(card.position)
+                    self.pull_to_top(card)
 
     def remove_card_from_pile(self, card):
         """ Remove card from whatever pile it was in. """