Skip to content

Commit

Permalink
Merge pull request #3 from 4sushi/feat/small_refacto
Browse files Browse the repository at this point in the history
feat: small refacto
  • Loading branch information
4sushi authored Mar 6, 2024
2 parents 495f449 + 820e2ea commit 9e44b70
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 68 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
requires = ["setuptools>=61.0.0", "wheel", "setuptools_scm[toml]>=8.0.4"]
build-backend = "setuptools.build_meta"

[project]
name = "solitaire-game"
version = "0.0.8"
authors = [
{name = "4sushi"},
]
description = "Solitaire game (klondike), made with python & curses. Play in the terminal. For Linux, Mac OS and Windows."
readme = "README.md"
requires-python = ">=3.7"
keywords = ["game", "klondike", "solitaire", "curses"]
license = {text = "MIT"}
Expand All @@ -24,4 +24,6 @@ solitaire-game = "solitaire_game.main:main"
solitaire = "solitaire_game.main:main"

[project.urls]
Homepage = "https://github.com/4sushi/solitaire-game"
Homepage = "https://github.com/4sushi/solitaire-game"

[tool.setuptools_scm]
Binary file removed solitaire_game/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed solitaire_game/__pycache__/game.cpython-311.pyc
Binary file not shown.
Binary file removed solitaire_game/__pycache__/game_ui.cpython-311.pyc
Binary file not shown.
Binary file removed solitaire_game/__pycache__/main.cpython-311.pyc
Binary file not shown.
24 changes: 12 additions & 12 deletions solitaire_game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GameCards:
'clubs': {'name': 'clubs', 'color': 'black', 'icon': '♣'},
}

def __init__(self, min_value: int=1, max_value: int=13):
def __init__(self, min_value: int = 1, max_value: int = 13):
self.cards: List[Card] = []
for symbol in self.SYMBOLS.values():
for value in range(min_value, max_value+1):
Expand All @@ -43,7 +43,7 @@ def __init__(self, min_value: int=1, max_value: int=13):
def mix_cards(self):
random.shuffle(self.cards)

def withdraw_cards(self, quantity: int=1) -> List[Card]:
def withdraw_cards(self, quantity: int = 1) -> List[Card]:
if quantity > len(self.cards):
raise ValueError('Error withdraw cards - Not enough cards in the game')
cards: List[Card] = self.cards[0:quantity]
Expand All @@ -64,7 +64,7 @@ def __init__(self):

self.final_stacks: FinalStacks = FinalStacks()

self.areas = { # area id => area params
self.areas = { # area id => area params
'1': {'name': 'deck'},
'2': {'name': 'final_stacks', 'i_stack': 0},
'3': {'name': 'final_stacks', 'i_stack': 1},
Expand All @@ -82,9 +82,9 @@ def __init__(self):
def action_switch_deck_cards(self):
self.deck.switch_cards()

def handle_action_move_cards(self, src_area_id: str, dest_area_id: str, quantity:int=1):
src_params = self.areas[src_area_id]
dest_params = self.areas[dest_area_id]
def handle_action_move_cards(self, src_area_id: str, dest_area_id: str, quantity: int = 1):
src_params: Dict = self.areas[src_area_id]
dest_params: Dict = self.areas[dest_area_id]

id_deck = [k for k, v in self.areas.items() if v['name'] == 'deck']
id_final_stacks = [k for k, v in self.areas.items() if v['name'] == 'final_stacks']
Expand Down Expand Up @@ -164,10 +164,10 @@ def is_game_won(self) -> bool:

class Deck:

NB_VISIBLE_CARDS:int = 3
NB_VISIBLE_CARDS: int = 3

def __init__(self, game_cards: GameCards):
self.cards:List[Card] = game_cards.withdraw_cards(quantity=24)
self.cards: List[Card] = game_cards.withdraw_cards(quantity=24)
self.i_deck_min: int = 0
self.i_deck_max: int = 0

Expand Down Expand Up @@ -223,7 +223,7 @@ def can_put_cards(self, cards: List[Card]) -> bool:
if self.count_visible_cards() == 0:
return top_card.get_str_value() == 'K'
else:
bottom_card:Card = self.get_pickable_cards(quantity=1)[0]
bottom_card: Card = self.get_pickable_cards(quantity=1)[0]
return bottom_card.color != top_card.color and bottom_card.value == (top_card.value+1)

def put_cards(self, cards: List[Card]):
Expand All @@ -235,7 +235,7 @@ def pick_cards(self, quantity: int):
self.turn_hidden_card_face_up()

def turn_hidden_card_face_up(self):
card:Card = self.hidden_cards.pop()
card: Card = self.hidden_cards.pop()
self.visible_cards = [card]


Expand Down Expand Up @@ -274,7 +274,7 @@ def can_put_card(self, card: Card) -> bool:
if self.count_cards() == 0:
return card.get_str_value() == 'A'
else:
top_card:Optional[Card] = self.get_pickable_card()
top_card: Optional[Card] = self.get_pickable_card()
return top_card.value == (card.value-1) and top_card.symbol == card.symbol

def put_card(self, card: Card):
Expand All @@ -295,4 +295,4 @@ def __init__(self):
self.stacks.append(final_stack)

def get_stack(self, i_stack: int) -> FinalStack:
return self.stacks[i_stack]
return self.stacks[i_stack]
Loading

0 comments on commit 9e44b70

Please sign in to comment.