Simple Blackjack game
You should follow the style guide. I was thinking that NewBlackjackGame was an odd name for a class, but it turns out it's a function; it should therefore be new_blackjack_game. (That being said, I think all of the logic in that function should really be in Game, see below.)
There is no point having a main that just calls one other function. Either rename that function to main, or call the function directly if __name__ == "__main__":.
You only need to hold the values for face cards in the values_lookup, which should be a class attribute (it's the same for all cards/decks). The card's value can just be an integer for non-face cards, then you can dict.get either the face card value or use it directly. For example:
class Card: FACES = {'Ace': 1, 'Jack': 10, 'Queen': 10, 'King': 10} def __init__(self, face, suit): self.face = face self.suit = suit def __str__(self): return "{0.face} of {0.suit}".format(self) @property def value(self): return self.FACES.get(self.face, self.face)
Note the use of @property, which is a Pythonic way to implement the getters and setters used in other languages. In use:
> c = Card("Ace", "spades") >> str(c) 'Ace of spades' >> c.value 1 >> c = Card(9, "diamonds") >> str(c) '9 of diamonds' >> c.value 9
As already pointed out, don't hard-code the name of the Players. If you keep the Dealer separate, you can have as many others as you like:
class Game: def __init__(self, *players, start_credit=100): self.dealer = Dealer self.deck = Deck self.players = [Player(player, start_credit) for player in players] ...
Then play like:
game = Game("Anna", "Bob", "Chris") game.play # replaces `NewBlackjackGame`
I think the main issue is having logic in odd places. I would suggest a structure like the following:
Even within the existing classes, your logic is all over the place. Consider this simplified implementation of Hand:
class Hand: def __init__(self): # initialise the empty list of cards def draw_from(self, deck): # draw a card from the deck and add to list def return_to(self, deck): # empty list of cards and return to deck @property def value(self): # all the value logic goes here
Questron is a fantasy role-playing video game series produced by Strategic Simulations, Inc.
In Questron the player takes on the role of a young serf who tries to make a name for himself by traveling the realm in order to gain the power and experience necessary to defeat the wicked "Mantor", ruler of the "Land of Evil".
The gameplay and...