/* CMSHN1201 Programming Workshop - Referral Coursework 2000/01 */ /* Playing card shuffler and dealer simulator */ /* Description...... Seed Rand function Initialise a new pack of cards do { Clear the screen Display game heading Display menu Prompt for and accept user's choice switch (users choice) { 1 : ---Play cards Shuffle the pack Deal 5 cards to player and dealer Clear the playing area on screen Display hand contents heading Display player's hand of cards and value Display dealer's hand of cards and value if player's hand worth more than dealer's { Display 'player won' message Add 1 to number of card games won } else if players hand worth less than dealer's Display 'Dealer won' message else Display 'draw' message Prompt for and accept any key to return to menu Add 1 to number of card games played 2 : ---Play dice Clear playing area on screen Display headings for point to make and dice value thrown Prompt for and accept any key to make first roll of dice roll the dice and store sum of the roll display dice roll and sum switch (sum) { 7, 11 : Set gamestatus = 1 (win on first roll) 2, 3, 12 : Set gamestatus = 2 (lost on first roll) default : Set gamestatus = 0 make myPoint = sum display point to make (myPoint) } while (not won or lost) (gamestatus is 0) { Prompt for and accept any key to roll again roll the dice and store sum Display dice roll and sum if sum = point to make set gamestatus = 1 (a win) else if sum is 7 set gamestatus = 2 (a seven loses) } if player won { Add 1 to number of dice games won Display 'Player wins' message } else Display 'Player loses' message prompt for and accept any key to return to menu Add 1 to number of dice games played } } while (user not choose Quit) Display 'You won x/y card games and n/m dice games' message Prompt for and accept any key to quit program */ #include #include /* Holds definition of 'rand' function */ #include /* Get time of day to seed 'rand' function */ #include #include #include "cards.h" #include "functions.h" /* Define the starting coordinates for screen output */ #define X 25 #define Y 9 /* Function prototypes */ void openPack (card [52]) ; void shuffle (card [52]) ; void deal (card [52], card [5], card [5]) ; void displaycard (card) ; int rollDice (int*, int*) ; void clearClient (int, int, int) ; int handValue (card [5]) ; main () { card pack [52] ; card playersHand [5] ; card dealersHand [5] ; int userResponse; int counter ; int die1, die2, sum, myPoint, gameStatus, x, y, cardsWon = 0, cardsPlayed = 0, diceWon = 0, dicePlayed = 0 ; srand (time (NULL)) ; /* Seed the rand function to ensure 'true' random numbers */ }