All pastes #1340731 Raw Edit

Craps.cpp

public cpp v1 · immutable
#1340731 ·published 2009-02-18 03:57 UTC
rendered paste body
/* * Craps.cpp * contains the rules of the game * * Assignment 4, Craps * SID: 995050550 * Author: Crystal Tse * Due: February 17, 2009 * Class: ECS 40, Winter 2009 */#include "Craps.h"Craps :: Craps()				// default constructor{	rollSum = 0;	nthRoll = 0;				// keeps track of # of rolls per game	point = 0;	winOnFirst = 0;	loseOnFirst = 0;	bettingStrategy = ' ';}Craps :: ~Craps()				// destructor{}void Craps :: collectBet(char choice)		// function to get player's bet; takes in one						// parameter to specify player's betting strategy						// A: bets $1 before each roll						// B: bet doubles before each roll{	bettingStrategy = choice;	switch (bettingStrategy) {	case 'A':		p.betOneDollar();		break;	case 'B':		p.betDouble();		break;	}}void Craps :: play()					// function to play craps{	nthRoll++;	rollSum = d.roll();				// roll the dice	if(nthRoll == 1)				// on the 1st roll	{		if(rollSum == 7 || rollSum == 11)	// if roll is 7 or 11		{			p.win();			// the game is won			winOnFirst++;			nthRoll = 0;		}		else if(rollSum == 2 || rollSum == 3 || rollSum == 12)	// if roll is 2, 3, or 12		{			p.lose();			// the game is lost			loseOnFirst++;			nthRoll = 0;		}		else					// if roll is any other number		{			point = rollSum;		// the roll becomes the 'point'			collectBet(bettingStrategy);	// get player's bet			play();				// roll and play again		}	}	else						// on subsequent rolls	{		if(rollSum == 7)			// if roll is 7		{			p.lose();			// the game is lost			nthRoll = 0;		}		else if(rollSum == point)		// if roll duplicates the point		{			p.win();			// the game is won			nthRoll = 0;		}		else					// if roll is any other number		{			collectBet(bettingStrategy);	// get player's bet			play();				// roll and play again		}	}}int Craps :: gameWins(){	return p.getWins();}int Craps :: winsOnFirstRoll(){	return winOnFirst;}int Craps :: lossesOnFirstRoll(){	return loseOnFirst;}int Craps :: getNumberOfGame()				// function to get the game number{	return p.getNumGames();}int Craps :: getPlayersMoney()				// function to get amount of money in player's wallet{	return p.getWallet();}int Craps :: getBetAmount(){	return p.getBet();}void Craps :: getDiceProbability(){	d.getProbability();}int Craps :: getRoll(){	return rollSum;}