10.5. Designing a Card Game Using clsCardDeck

Now that you have a class that is capable of shuffling a deck of cards and dealing them out one at a time, let's design a very simple card game. The card game is a simplification of one called "In Between."

Try It Out: In Between Card Game

Our variation of this game begins with the dealer (the computer) giving you a hundred dollars to wager. The dealer then deals two cards face up. You may wager nothing on a game, or you may wager up to all of the credit you have. If you don't want to bet, simply click the Deal button again to deal another set of cards. If you make a wager, the dealer deals the next card. If that card falls within the range formed by the other two cards, you win an amount equal to your wager. Your winnings are automatically added to your balance. If the third card falls outside the range of the first two cards, the dealer wins and your balance is reduced by the amount of your wager. If the third card equals either of the two first cards, the dealer wins. Aces are considered to have the lowest value (one) in the deck and the king (13) the highest.

A sample run is shown in Figure 10-6

Figure 10-6. Figure 10-6

For example, if the first two cards are AS and 9H and the third card is QH, the player loses because the third card (a queen, or 12) falls outside the range of 1 to 9. If the third card is an ace or a nine of ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.