DEV Community

AddictedtoCreatine
AddictedtoCreatine

Posted on

My First Console Game in Python: Blackjack.

Hi there, and thanks so much for taking the time to read my first blog post. In order to re-sharpen my object-oriented and Python programming skills back to their former glory, I have created a basic, but interactive, program that simulates a game of Blackjack between any number of players.

Image description

I have taken a decent amount of steps to complete this program/game. For example, the program has been modularized as much as possible, utilizing two classes, 'Game' and 'Player', which primarily hold vital data that is constantly used and updated from the 'main()' function (e.g. player score, player name, game description, etc.). The 'Game' class has a very important class variable in the 'dict_of_cards', which holds a dictionary of available cards; this dictionary is used to pull and remove cards constantly as the game progresses through each round, acting as a sort of dealer, if you will. I have also created a file, 'helpers.py', which is used to keep a multitude of helper functions that the 'main()' function calls; this de-cluttered the 'main()' function significantly, down to 68 lines of code. Lastly, I have imported and used some external Python libraries; particularly the 'random' library, which handles the logic of pulling cards from the card dictionary in a completely unbiased way (As opposed to the built-in 'pop_item()' function, which runs the risk of not re-ordering the dictionary items.).

Here's the GitHub link, if you would like to clone the repository and play the game in your own terminal: https://github.com/kchoward48/CS101_Portfolio.git

This was a really nice step back into object-oriented programming, which I really hadn't done too much of since my days at Purdue University. It was also really nice to practice those skills in my language of choice, Python. Thank you so much for reading, and happy coding.

Top comments (0)