main

/*

Programmer: Jennifer Leopold

Date: April 6, 2018

File: hw9.cpp

Purpose: ...

To compile: g++ hw9.cpp ... -o hw9

To execute: ./hw9

*/

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <ctime>

#include "path.h"

#include "rescue.h"

#include "player.h"

#include "card.h"

#include "cardDeck.h"

using namespace std;

const unsigned int NUM_SIDES_REGULAR_DIE = 6;

const unsigned int NUM_PLAYERS = 4;

const unsigned int NUM_MOVES = 3; // for testing

void getPlayerInfo(string &name, Pawn &pawnColor,

const bool availableColors[NUM_PAWN_COLORS]);

void getPlayers(Player p[], const int numPlayers);

void getPlayerInfo(string &name, Pawn &pawn,

const bool availableColors[NUM_PAWN_COLORS])

{

bool validPawnColor;

unsigned int pawnColor;

cout << "\nEnter your name: ";

getline(cin, name);

do

{

cout << "Available pawn colors are:\n";

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

if (availableColors[i])

cout << i << " = " << PAWN_COLORS[i] << endl;

cout << "Enter your pawn color selection number: ";

cin >> pawnColor;

cin.ignore(500, '\n');

validPawnColor = (pawnColor >= 0) &&

(pawnColor < NUM_PAWN_COLORS) &&

availableColors[pawnColor];

if (!validPawnColor)

cout << "That is not a valid selection!\n";

} while (!validPawnColor);

pawn = static_cast<Pawn>(pawnColor);

return;

}

void getPlayers(Player p[], const int numPlayers)

{

bool availableColors[NUM_PAWN_COLORS];

string name;

Pawn pawnColor;

for (unsigned int i = 0; i < NUM_PAWN_COLORS; i++)

availableColors[i] = true;

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

{

getPlayerInfo(name, pawnColor, availableColors);

p[i] = Player(name, pawnColor);

availableColors[pawnColor] = false;

}

return;

}

int main()

{

srand(time(NULL));

Player players[NUM_PLAYERS];

unsigned int dieRoll;

unsigned int pos;

CardDeck cardDeck;

Card nextCard;

// Get the player info

getPlayers(players, NUM_PLAYERS);

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

cout << players[i];

// Intialize the deck of cards

cardDeck.initializeFromFile();

cout << cardDeck << endl;

// Have each player do certain things NUM_MOVES many times

for (int move = 1; move <= NUM_MOVES; move++)

{

for (int p = 0; p < NUM_PLAYERS; p++)

{

// Roll 6-sided die and move that many spaces on path

dieRoll = (rand() % NUM_SIDES_REGULAR_DIE) + 1;

cout << players[p].PawnToString() << " player rolls "

<< dieRoll << "...";

if (players[p].move(dieRoll))

{

pos = players[p].getPath().getCurrentPosition();

cout << "is now at position " << pos

<< " which is a '"

<< PATH_ENTRIES[players[p].getPath().

getPathEntryAtPosition(pos)]

<< "'\n";

}

else cout << "can't move that much, "

<< "would go off the path!\n";

// Draw a card from the deck

nextCard = cardDeck.getNextCard();

cout << players[p].PawnToString()

<< " player draws card:\n" << nextCard << endl;

// Roll 'rescue' die

dieRoll = rand() % NUM_RESCUES;

cout << players[p].PawnToString()

<< " player rolls rescue die and gets: "

<< RESCUES[dieRoll].description << endl;

// See if 'rescue' die matches card's rescue label

cout << "The rescue die symbol ";

if (nextCard.getRescueSymbol() == RESCUES[dieRoll].code)

cout << "matches";

else cout << "doesn't match";

cout << " the rescue symbol on the card.\n\n";

}

cout << endl << endl;

}

return 0;

}