Solitaire_10.py diff#
solitaire_10.py#
--- /pb1/repo/arcade/doc/tutorials/card_game/solitaire_09.py
+++ /pb1/repo/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,23 @@
# 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, hit_box_algorithm="None")
+ self.is_face_up = False
+ super().__init__(FACE_DOWN_IMAGE, scale, hit_box_algorithm="None")
+
+ 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):
@@ -180,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
@@ -209,23 +230,29 @@
# Might be a stack of cards, get the top one
primary_card = cards[-1]
+ assert isinstance(primary_card, Card)
+
# 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. """