In part 1 we created our Card class, in part 2 we created our Deck and Hand class. Now in this final part let’s create our form using all the classes we’ve done before.
Create a new form with the size of 1000*400. Its FormBorderStyle should be FixedSingle. Place a MenuStrip on it (only for further developments, for example: new game, score table, etc.) and a SplitContainer with 2 horizontal panels on it. You also need 2 buttons (hit and stay) and 3 labels to show scores and computer action if it STAYs.
The form should look like something like this:
Let’s create some class-level variables (so you can reach them from every method):
private readonly int STARTING_HAND = 2; private readonly int MAX_CARDS_ON_TABLE = 11;//worst case: you could have maximum 11 cards in hand (four 2s + four 3s + four 1s = 21) PictureBox p; PictureBox q; Deck deck; Hand player; Hand computer; int computerSum; int playerSum;
The first 2 variables are readonly one. It could be const, if you prefer that one, doesn’t matter. PictureBox p and q are for the 11-11 pictureboxes that will be placed onto the table for each gamblers: p for computer, q for player. We also have a deck and 2 hands and of course the 2 total points in computerSum and playerSum.
We will have only 6 methods on our form:
- NewGame – resets the form, clears the table, initializes the card places, resets the scores
- ClearTable
- InitializeCardPlacesOnTable
- btnHit_Click
- btnStay_Click
- computerHit