crazyDarts.h

// Nathan Eloe October 24 2013

// crazyDarts.h

// Function prototypes for Moe's harebrained darts game

#ifndef CRAZYDARTS_H

#define CRAZYDARTS_H

#include <string>

using namespace std;

const float BOARD_DIST = 11.0;

const float TO_RADIANS = 0.017453;

const int RAND_BEER_FACTOR = 2;

const int MAX_RAND_SCOREX10 = 55;

// Desc: calcualtes the horizontal distance from the origin

// based on a horizontal angle and BOARD_DIST

// Pre: gamma is in degrees

// Post: returns the horzontal distance from the origin (the x coordinate)

float xCoord (const int gamma);

// Desc: calculates the vertical distance from the origin based on an angle

// of elevation (theta), a horizontal angle (gamma), and a BOARD_DIST

// Pre: theta, gamma in degrees

// Post: Returns the vertical distance from the origin (the y coordinate)

float yCoord (const int theta, const int gamma);

// Desc: returns a random angle based on the number of beers

// Pre:

// Post: returns a random number in the closed interval

// [-RAND_BEER_FACTOR*beers, RAND_BEER_FACTOR*beers]

int randAngle(const int numBeers);

// Desc: returns the distance between the origin and the point x,y

// Pre:

// Post: returns sqrt(x*x+y*y)

float vecLength(const float x, const float y);

// Desc: Outputs the information for a throw

// Pre:

// Post: outputs the throw information to the screen

void displayThrow(const float x, const float y, const float score,

const string sound);

// Desc: Calculates the score of the user based on the number of beers

// Pre:

// Post: Calculates and returns the score

int score(const int beers);

// Desc: Calculates the score of the user based on the per-throw score

// Pre: numScores <= the maximum number of elements in scores

// Post: Calculates and returns the score

float score(const float scores[], const int numScores, const int beers);

// Desc: Calculates the score of the user based on the per-throw score

// Pre: numScores <= the maximum number of elements in scores

// Post: Calculates and returns the score

float score(const float scores[], const int numScores);

// Desc: Plays the dart game for a specified number of rounds

// Pre: numRounds <= the maximum number of elements in scores

// numSounds <= the maximum number of elements in sounds

// Post: the first numRounds elements of the array is populated with scores

// Outputs dart location, score, and a sound for each round"

void play(float scores[], const int numRounds,

const string sounds[], const int numSounds, const int numBeers);

// Desc: Plays the dart game for a specified number of rounds if the

// player is too drunk

// Pre: numRounds <= the maximum number of elements in scores

// Post: the first numRounds elements of the array is populated with

// random scores

void play(float scores[], const int numRounds);

// Desc: Seeds the random number generator if it has not been seeded before

// Pre:

// Post: the random number generater is seeded with time(NULL) if it has not

// already been seeded

void seed();

//Desc: Display's the user's score

//Pre:

//Post: The score is displayed to the screen with a message

void displayScore(const float score);

//Desc: Gets a y or an n from the user

//Pre:

//Post: returns 'y' or 'n'

char getYorN();

// Desc: averages the contents of an array

// Pre: 0 < dataSize <= the maximum number of elements in the array

// The += operator for two T types must be defined

// The resulting type of T+T must have the / operator defined between

// itself and a float

// Post: returns the average of the elements in the array

template <typename T>

T average(const T array[], const int numElts)

{

T sum = 0;

for (int i=0; i<numElts; i++)

sum += array[i];

return sum / static_cast<float>(numElts);

}

// Desc: calculates the variance of the contents of an array

// Pre: 0 < dataSize <= the maximum number of elements in the array

// The += operator for two T types must be defined

// The / operator between two elements of type T must be defined

// The resulting type of T+T must have the / operator defined between

// itself and a float

// Post: returns the sample variance of the array's contents

template <typename T>

T variance(const T array[], const int numElts)

{

T avg = average(array, numElts);

T sum = 0;

for (int i=0; i<numElts; i++)

sum += (array[i] - avg) * (array[i] - avg);

return sum / static_cast<float>(numElts);

}

// Desc: determines the minimum of two values

// Pre: the < operator must be defined for type T

// Post: returns the lesser of the two parameters

template <typename T>

T Min(const T& val1, const T& val2)

{

return val1 < val2 ? val1 : val2;

}

#endif