DEV Community

nineismine
nineismine

Posted on

Let’s build a basic Blackjack App using C# and the Console Part 1 - The Design

Designing a Blackjack App

cards

Software design practices and good habits!

When you are just starting out as a new software engineer it can be tempting to skip over some of the things that not only make your job easier , but also tend to make the quality of your code a little higher. As a freshman engineer I would often find myself skipping right to coding without even planning what I was going to code. So in the spirit of teaching you the RIGHT way to do things let's talk about the bare minimum we need to do , and then let's get to coding a more complicated app. We're going to build a Blackjack app using the Console the quickest way that we can and then after we will talk a little bit about some better ways to build this app. Designing a Blackjack App will be a good way for us to talk a little bit about some of the different variable types, do some basic math functions, create and use methods, and even start to talk about classes. This will all be used to further our goal of learning about C# and software engineering.

Design

 

Requirements

Normally in a professional environment you will start with requirements for your project. These requirements will typically be provided by a stakeholder. Since we don't have an external stakeholder lets take a second and write down some basic requirements for designing a BlackJack App and get a little closer to our goal of learning about C#.

  • The player will receive 2 cards
  • The dealer will receive 2 cards
  • Ask the player to hit or stay (and maybe split of double in a different version)
  • The players cards will be totaled and displayed
  • The cards will emulate a the typical cards you see in a card deck
  • Do not display Suits.
  • New cards will be from 2 to ACE
  • If the card is an ace the player or dealer will select 1 or 11 (out of scope for first build)
  • If any hand is over 21 the owner will bust and lose
  • Display all output to console
  • At the end of the game display an option to play another game or quit

Designing a Blackjack App- The Technical Design

Now that we are on to talking about design. It's good a good idea to mention there are many ways to complete a technical design. Some software development methods require very detailed technical designs others just focus on creating a rough idea of the application. In these cases you usually focus more on the acceptance criteria than writing out details about how we will get to the end result.

Because we want to get to the coding as soon as possible we will just do a basic design. There are a lot of ways to tackle this so one persons design for a game like this might vary greatly from another persons.

Things that we will need to manage the game

  • Create a class or some way to represent a card
    • a card has a value
    • a type (king , queen , numeric etc)
  • Create a collection for the players cards and the dealers
  • Create a method to calculate the numeric value of "hand"
  • Determine if the hand is over 21
  • Create a method to display the cards in a hand (possibly for the advanced version only)
  • Create a method to get a new card from the dealer by rolling a random number from 2 to 14 with 11 representing a jack 12 a queen 13 - king and 14 Ace

[caption id="attachment_241" align="aligncenter" width="300"]The Loop The Loop[/caption]

Designing a Blackjack App - The game loop

 

  • When the game starts we will get 2 new cards for the player and 2 for the dealer
  • Display the dealers second card to the player
  • Total the players cards and display them
  • Ask the Player to type H for hit or S for stay
    • Accept a uppercase or lower case response
  • If the player chooses to "hit" another card will be drawn and the loop will continue until the player stays or busts
  • After the player decides to "stay" the dealer's turn will commence
  • The dealer will follow Standard black jack rules
    • When the dealer has served every player
    • The dealer's face-down card is turned up
    • If the total is 17 or more, the dealer must stand.
    • If the total is 16 or under, the dealer must hit.
    • The dealer must continue to take cards until the total is 17 or more, at which point the dealer must stand.
  • When the dealer stands, or busts the game is over.
  • If the dealer busts, the player wins
  • If the dealer does not bust, the total of the two hands is compared and the person with the highest total wins.
  • Ask the Player to quit or play again

Now lets get to the learning about C# part...Next up... lets code a basic version of Blackjack utilizing as few C# features as possible.

 









Latest comments (3)

Collapse
 
lewisnielsen profile image
lewisnielsen • Edited

This is a very useful and interesting post. I've never built an app like this, but I want to try it one day.
I like playing such games, so I hope that soon I'll be able to create and play my own game. But to be honest, nowadays there are so many sites with games, and it will be hard to create something even better. I play often on different sites, and can say that the casino games, not only poker are so well developed. I always read reviews and other info about them and from this page gamblizard.ca/best-canadian-online... I found out some new info about casinos which use Interact. It's a good payment processor and I can say that I like casinos that use it even more. So for now I'll just play and enjoy, and then will see if the development is even worth it.

Collapse
 
jacobhendriks1 profile image
jacobhendriks1

Wow, that's very useful information,thank you!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.