C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1

B. The Draw Poker Program


Programming is not all work and no play, and the following Draw Poker game proves it! The game
program provides a long example that you can study as you master C. Although the game is simple and
straightforward, a lot happens in this program.


As with all well-written programs, this one is commented thoroughly. In fact, if you have read each
chapter of this book, you will understand the programming of Draw Poker. One of the reasons the
program is kept simple is to keep it compiler-independent. For your program, you might want to find
out how your C compiler produces colors onscreen so that you can add pizazz to the game’s display.
Also, when you master enough of C to understand the program’s inner workings, you’ll want to
explore graphics capabilities and actually draw the cards.


Note

You can also experiment with changes to the program. For example, most draw poker
programs pay out on a pair only if it is Jacks or better (that is, only a pair of Jacks,
Queens, Kings, or Aces). How would you have to alter the analyzeHand()
function to make that change?

Click here to view code image


// Example poker program from Appendix B of Absolute Beginner's
// Guide to C, 3rd Edition
// File AppendixBpoker.c
/* This program plays draw poker. Users can play as often as they
want, betting between 1 and 5. They are dealt 5 cards and then get
to choose which cards to keep, and which cards to replace. The new
hand is then reviewed and the user's payout is set based on the
value of the hand. The user's new bankroll is displayed as they are
given
the option to continue. */
// Header files
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
// Two constants defined for determining whether hands are flushes
// or straights
#define FALSE 0
#define TRUE 1
// Function prototyping
Free download pdf