Skip to content

Commit e457271

Browse files
authored
Merge pull request #27 from fabi200123/add-double-click
Add double-click option
2 parents 0a53f88 + 62695ef commit e457271

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

CHANGELOG/CHANGELOG-1.2.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- [v1.0.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.0.0)
66
- [v1.1.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.1.0)
7-
- [v1.2.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.1.0)
7+
- [v1.2.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.2.0)
88

99

1010
> **NOTE** The code is based on the tutorial from [Python Arcade 2.6.17](https://api.arcade.academy/en/latest/tutorials/card_game/index.html)

CHANGELOG/CHANGELOG-1.3.0.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# TBA - Updates on master branch
2+
3+
# Solitaire Game
4+
5+
## Current versions
6+
7+
- [v1.0.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.0.0)
8+
- [v1.1.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.1.0)
9+
- [v1.2.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.2.0)
10+
- [v1.3.0](https://github.com/fabi200123/Solitaire-Game/releases/tag/v1.3.0)
11+
12+
> **NOTE** The code is based on the tutorial from [Python Arcade 2.6.17](https://api.arcade.academy/en/latest/tutorials/card_game/index.html)
13+
14+
### Why did I do this?
15+
I have decided to create my own Solitaire game because almost all current games use ADS or other stuff that I mostly don't enjoy having there.
16+
Oh... And I love Solitaire as my time waste game : )
17+
18+
### How did I do it?
19+
20+
- Thought about the concept in my mind, tried to come up to something similar to the default Solitaire Game
21+
- Graphic for the cards will be created by me, probably using **Paint.net** or **Aseprite**
22+
- Code will be written in **Python**
23+
24+
### Changelog since v1.2.0
25+
26+
- Added double-click option to automatically add cards in top-piles

game/game.py

+34-8
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ def __init__(self, language="EN"):
358358
# Number of points the user has
359359
self.moves = 0
360360

361+
# Last click time for double-click detection
362+
self.last_click_time = 0
363+
361364

362365
def setup(self, hard_mode: bool, language="EN"):
363366
'''Set up the game and also restart the game'''
@@ -532,7 +535,11 @@ def on_mouse_press(self, x, y, button, key_modifiers):
532535
for i, card in enumerate(self.held_cards):
533536
card.position = self.held_cards_original_position[i]
534537
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+
536543
# Get list of cards that were clicked
537544
cards = arcade.get_sprites_at_point((x, y), self.card_list)
538545

@@ -545,7 +552,20 @@ def on_mouse_press(self, x, y, button, key_modifiers):
545552
# Figure out which pile the card is in
546553
pile_index = self.get_pile_for_card(top_card)
547554

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:
549569
if self.hard_mode:
550570
# Move all face up cards to the position of the face up mat pile
551571
for card in self.piles[BOTTOM_FACE_UP_PILE]:
@@ -627,6 +647,13 @@ def on_mouse_press(self, x, y, button, key_modifiers):
627647
self.piles[BOTTOM_FACE_DOWN_PILE].append(card)
628648
card.position = self.pile_mat_list[BOTTOM_FACE_DOWN_PILE].position
629649

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+
630657
def remove_card_from_pile(self, card):
631658
'''Remove the card from the pile'''
632659
for pile in self.piles:
@@ -767,10 +794,7 @@ def on_mouse_release(self, x, y, button, key_modifiers):
767794
self.held_cards = []
768795

769796
# --- 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()
774798

775799
def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
776800
""" User moves mouse """
@@ -794,8 +818,10 @@ def check_winning(self):
794818
'''Check if the player has won the game'''
795819
for pile in self.piles[TOP_PILE_1:]:
796820
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)
799825

800826
def main():
801827
'''Main function to run the game'''

0 commit comments

Comments
 (0)