-
Notifications
You must be signed in to change notification settings - Fork 2
display_card #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChretienCml
wants to merge
3
commits into
bug_fix
Choose a base branch
from
display_card
base: bug_fix
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
display_card #48
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from src.humans.player import Player | ||
| from src.cards.deck import Deck | ||
| from src.common.constants import Decision | ||
| from src.controller.card_area_organizer import CardAreaOrganizer | ||
|
|
||
| import pygame | ||
| from pygame.locals import ( | ||
|
|
@@ -43,6 +44,19 @@ def __init__(self, window): | |
| self.hand_idx = None | ||
| # self.view_game = View_game(window, view_config) | ||
|
|
||
| # Organizers | ||
| self.card_area_organizer = CardAreaOrganizer() | ||
|
|
||
| self.organizers = ( | ||
| self.card_area_organizer, | ||
| ) | ||
|
|
||
| self.subscribe_to_organizers() | ||
|
|
||
| def subscribe_to_organizers(self): | ||
| for organizer in self.organizers: | ||
| organizer.areas_updated.attach(self.refresh) | ||
|
|
||
| def game_launch(self): | ||
| self.view_game = ViewGame(self.window) | ||
| self.view_game.buttons["card"].signal.attach(self.btn_card) | ||
|
|
@@ -67,7 +81,7 @@ def initiate_players(self): | |
| self.add_human(Player(name_of_player, self.player_wallet)) | ||
|
|
||
| def refresh(self): | ||
| self.view_game.refresh() | ||
| self.view_game.refresh(self.card_area_organizer) | ||
|
|
||
| def enable_buttons(self, *btn_names): | ||
| """ | ||
|
|
@@ -131,6 +145,7 @@ def first_round(self): | |
| for human in self.humans_list: | ||
| human.clear_hands() | ||
| self.dealer.clear_hand() | ||
| self.card_area_organizer.clear_areas() | ||
|
|
||
| # Set buttons state | ||
| self.enable_buttons("bet", "quit") | ||
|
|
@@ -165,13 +180,22 @@ def first_round(self): | |
| for self.human in self.humans_list: | ||
| print(self.human.name + "is receiving cards.") | ||
| # at initialization we only change the first hand of the player with 2 cards | ||
| self.human.add_card(self.deck.getCard(), 0) | ||
| self.human.add_card(self.deck.getCard(), 0) | ||
| human_card = self.deck.getCard() | ||
| human.add_card(human_card, 0) | ||
| self.card_area_organizer.add_card(human_card, "player", 0) | ||
|
|
||
| human_card = self.deck.getCard() | ||
| human.add_card(self.deck.getCard(), 0) | ||
| self.card_area_organizer.add_card(human_card, "player", 0) | ||
|
|
||
| # giving the dealer a hand (with 2 card) | ||
| self.dealer.add_card(self.deck.getCard()) | ||
| self.dealer.add_card(self.deck.getCard()) | ||
| print("End bet_round") | ||
| dealer_card = self.deck.getCard() | ||
| self.dealer.add_card(dealer_card) | ||
| self.card_area_organizer.add_card(dealer_card, "dealer", 0) | ||
|
|
||
| dealer_card = self.deck.getCard() | ||
| self.dealer.add_card(dealer_card) | ||
| self.card_area_organizer.add_card(dealer_card, "dealer", 0) | ||
| return True | ||
|
|
||
| def play_one_round(self): | ||
|
|
@@ -222,7 +246,9 @@ def play_one_round(self): | |
| while dealer_decision != Decision.stand: | ||
| print(dealer_decision) | ||
| if dealer_decision == Decision.hit: | ||
| self.dealer.add_card(self.deck.getCard()) | ||
| dealer_card = self.deck.getCard() | ||
| self.dealer.add_card(dealer_card) | ||
| self.card_area_organizer.add_card(dealer_card, "dealer", 0) | ||
| print("Dealer hand : " + str(self.dealer.hand)) | ||
| dealer_decision = self.dealer.choose_action() | ||
|
|
||
|
|
@@ -259,6 +285,9 @@ def btn_card(self): | |
| print("Is burnt or black jack") | ||
| self.playing = False | ||
|
|
||
| print("add card into card organizer for display purpose") | ||
| self.card_area_organizer.add_card(card, "player", self.hand_idx) | ||
|
|
||
| print("btn_card") | ||
|
|
||
| def btn_bet(self): | ||
|
|
@@ -316,3 +345,11 @@ def btn_quit(self): | |
| self.quit = True | ||
|
|
||
| print("btn_quit") | ||
|
|
||
| @classmethod | ||
| def get_card_organizer(cls): | ||
| """ | ||
| give the card organizer | ||
| :return: CardAreaOrganizer | ||
| """ | ||
| return cls.card_area_organizer | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at end of file
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at end of file |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python style !?