A simple blackjack game. This was completed as the milestone 2 project for Jose Portilla’s “Zero-to-Hero Python” course. Basic Python functionality inlcuding Object-Oriented programming practices were used to implement this project.
Pytest was used to write a number of tests and automatic testing has been setup with Travis CI.
Setup Travis CI:
- Create branch
git checkout -b travis_setup
- Add .travis.yml file
- Specify language
language: python
- Must provide a script
script: pytest
- No requirement.txt so need to override install
install: pip --version
- Create test_name.py file with tests
- Commit
Gameplay:
- Create a bank roll according to user to be used for all subsequent games
- Start the first round
- Ask the player for their bet for this round
- Make sure that the Player’s bet does not exceed their available chips
- Create a deck of 52 cards and shuffle
- Deal two cards to the Dealer and two cards to the Player
- Show only one of the Dealer’s cards, the other remains hidden
- Show both of the Player’s cards
- Ask the Player if they wish to Hit, and take another card
- If the Player’s hand doesn’t Bust (go over 21), ask if they’d like to Hit again.
- If a Player Stands, play the Dealer’s hand.
- The dealer will always Hit until the Dealer’s value meets or exceeds 17
- Determine the winner
- Adjust the Player’s chips accordingly to bank roll
- Ask the Player if they’d like to play again
- If so, start again from step 3
The game starts with an introduction and prompt for how many chips to start with (1) Dealer wins since they have a higher value than the player, lose the bet. (2) Payer wins since they have a higher value than the dealer, win the bet. (3) Both the dealer and the player have the same value, there is a tie and no change to players chips. (4) Betting more than available chips is not allowed. Player hits then stands, dealer busts so player wins and takes bet.__ _(5) Player bets all their chips, player hits and there is a tie. No change to chips. (6) Player bets all their chips, player hits and busts. Player has no balance left so the game ends.