Welcome to my Blackjack game! This is a simple text-based implementation of the popular casino card game. The objective of the game is to get a hand value as close to 21 as possible without exceeding it.
- The game is played with a standard deck of 52 cards.
- Each card has a value: numbered cards are worth their face value, face cards (J, Q, K) are worth 10, and the Ace can be worth either 1 or 11.
- At the start of the game, the player and the dealer are each dealt two cards.
- The player can choose to "hit" (draw another card) or "stand" (keep the current hand).
- If the player's hand value exceeds 21, they "bust" and lose the game.
- After the player's turn, the dealer reveals their second card and continues to draw cards until their hand value is 17 or higher.
- If the dealer's hand value exceeds 21, they "bust" and the player wins.
- If neither the player nor the dealer busts, the one with the hand value closest to 21 wins.
To play the Blackjack game, follow these steps:
- Clone this repository to your local machine.
- Navigate to the project directory in your terminal.
- Make sure you have Python installed on your machine.
- Run the following command to start the game:
python blackjack.py
- Follow the on-screen instructions to play the game.
That's it! Enjoy playing Blackjack in the terminal!
This is my second Python project, and it was more complex compared to my first project, Rock Paper Scissors. In this Blackjack game, I had to work with additional data structures such as tuples and utilize for loops and conditional logic.
The use of tuples
allowed me to represent the deck of cards and their values. I could easily access and manipulate the cards using indexing and slicing operations.
The for
loops were essential for iterating over the cards in the deck and calculating the hand values. I could iterate over the player's and dealer's hands to determine the total value and make decisions based on the game rules.
Conditional logic played a crucial role in implementing the game rules. I used if
statements to check for conditions such as busting, winning, and tying. Based on these conditions, I could determine the outcome of each round and the overall winner of the game.
In my recent refactoring, I focused on adhering to the Single Responsibility Principle (SRP) by breaking down functions into smaller, more manageable pieces. For example, I separated input validation logic from the main game loop, which made the code cleaner and easier to maintain. This refactoring also improved the readability and modularity of the code, making it easier to understand and extend.
Overall, this project expanded my understanding of Python programming concepts and introduced me to more advanced topics such as additional data structures, loops, and conditional statements. The refactoring process taught me the importance of writing clean, maintainable code by following principles like SRP. It's been a joy getting to see what Python offers and how it compares to my experience with JavaScript!