예제 #1
0
void main ()
{
	// Outputs the rules for the game
	outputIntro();

	string name;

	// Retrieve user's name and initialize the Player
	cout << "\nEnter your name: ";
	getline(cin, name);
	Player user(name);

	// Retrieve a name for the computer and initialize the computer
	cout << "\nEnter a name for the computer: ";
	getline(cin,name);
	Computer comp(name);
	cout << "\n";

	unsigned int roundCount = EMPTY;

	// Game continues as long as neither player has over WINNING_SCORE points
	while ( (user.GetScore() < WINNING_SCORE) && (comp.GetScore() < WINNING_SCORE) )
	{
		// Output scores
		ScoreOutput(user,comp,roundCount);

		// Initialize and shuffle up the deck
		Cards deck;
		deck.InitializeDeck();
		deck.ShuffleDeck();

		// Must clear up both the players and computers hands and melded card piles
		user.ClearHandAndMeldedCards();
		comp.ClearHandAndMeldedCards();

		// Deal the deck
		dealDeck(user,comp,deck,roundCount);
	
		// Reset count back to roundCount --> alternate who goes first
		unsigned int count = roundCount;

		// Commence the game, game continues as long as both players have cards
		while ( (user.GetHandSize() > EMPTY) && (comp.GetHandSize() > EMPTY) && (deck.GetDeckSize() > EMPTY) )
		{
			// Must call gameplay every play through the hand
			
			if (count % EVEN_ODD == EMPTY)	// Player is up
				user.GamePlay(deck,comp.ReturnVectorOfMyMeldedCards(),comp.GetName());
			else						// Computer is up
				comp.GamePlay(deck);

			count++;
		}
		// Round is over, must increment the round count
		roundCount++;

		int initialPlayerScore = user.GetScore();
		int initialCompScore = comp.GetScore();
		
		// Calculate scores
		user.CalculateScore();
		comp.CalculateScore();

		cout << "Points scored this round:\n" << user.GetName() << ": " << user.GetScore() - initialPlayerScore << "\n" <<
			comp.GetName() << ": " << comp.GetScore() - initialCompScore << "\n\n";
	}
	// Someone has won by now
	outputEnding(user,comp);

	system("pause");
}