@@ -358,6 +358,9 @@ def __init__(self, language="EN"):
358
358
# Number of points the user has
359
359
self .moves = 0
360
360
361
+ # Last click time for double-click detection
362
+ self .last_click_time = 0
363
+
361
364
362
365
def setup (self , hard_mode : bool , language = "EN" ):
363
366
'''Set up the game and also restart the game'''
@@ -532,7 +535,11 @@ def on_mouse_press(self, x, y, button, key_modifiers):
532
535
for i , card in enumerate (self .held_cards ):
533
536
card .position = self .held_cards_original_position [i ]
534
537
return
535
-
538
+
539
+ curr_time = time .time ()
540
+ double_click = curr_time - self .last_click_time < 0.3
541
+ self .last_click_time = curr_time
542
+
536
543
# Get list of cards that were clicked
537
544
cards = arcade .get_sprites_at_point ((x , y ), self .card_list )
538
545
@@ -545,7 +552,20 @@ def on_mouse_press(self, x, y, button, key_modifiers):
545
552
# Figure out which pile the card is in
546
553
pile_index = self .get_pile_for_card (top_card )
547
554
548
- if pile_index == BOTTOM_FACE_DOWN_PILE :
555
+ # If we double-clicked, try to move the card to a top pile
556
+ if double_click and top_card .is_face_up :
557
+ for top_pile_index in range (TOP_PILE_1 , TOP_PILE_4 + 1 ):
558
+ # If the card is the top card of the pile
559
+ if self .can_add_to_top_pile (top_card , top_pile_index ):
560
+ self .move_card_to_new_pile (top_card , top_pile_index )
561
+ top_card .position = self .pile_mat_list [top_pile_index ].position
562
+ top_card .is_face_up = True
563
+ self .pull_to_top (top_card ) # Adjust z-order
564
+ self .moves += 1
565
+ # --- Win check
566
+ self .check_winning ()
567
+ return
568
+ elif pile_index == BOTTOM_FACE_DOWN_PILE :
549
569
if self .hard_mode :
550
570
# Move all face up cards to the position of the face up mat pile
551
571
for card in self .piles [BOTTOM_FACE_UP_PILE ]:
@@ -627,6 +647,13 @@ def on_mouse_press(self, x, y, button, key_modifiers):
627
647
self .piles [BOTTOM_FACE_DOWN_PILE ].append (card )
628
648
card .position = self .pile_mat_list [BOTTOM_FACE_DOWN_PILE ].position
629
649
650
+ def can_add_to_top_pile (self , card , pile_index ):
651
+ '''Check if a card can be added to a top pile'''
652
+ if len (self .piles [pile_index ]) == 0 :
653
+ return card .value == 'A'
654
+ top_card = self .piles [pile_index ][- 1 ]
655
+ return top_card .suit == card .suit and CARD_VALUES .index (top_card .value ) + 1 == CARD_VALUES .index (card .value )
656
+
630
657
def remove_card_from_pile (self , card ):
631
658
'''Remove the card from the pile'''
632
659
for pile in self .piles :
@@ -767,10 +794,7 @@ def on_mouse_release(self, x, y, button, key_modifiers):
767
794
self .held_cards = []
768
795
769
796
# --- Win check
770
- if self .check_winning ():
771
- # Show the winning window
772
- view = WinningView (self .elapsed_time , self .moves , language = self .language )
773
- self .window .show_view (view )
797
+ self .check_winning ()
774
798
775
799
def on_mouse_motion (self , x : float , y : float , dx : float , dy : float ):
776
800
""" User moves mouse """
@@ -794,8 +818,10 @@ def check_winning(self):
794
818
'''Check if the player has won the game'''
795
819
for pile in self .piles [TOP_PILE_1 :]:
796
820
if len (pile ) != 13 :
797
- return False
798
- return True
821
+ return
822
+ # Show the winning window
823
+ view = WinningView (self .elapsed_time , self .moves , language = self .language )
824
+ self .window .show_view (view )
799
825
800
826
def main ():
801
827
'''Main function to run the game'''
0 commit comments