Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.147.6.176
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/jwmccreary/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jwmccreary/piratesgold3.cpp
// Pirate's Gold - a simulated form of solitaire
//
// September 2008
// CS 311
// Justin McCreary
// Professor: Dr. Ames
// file name: piratesgold3.cpp
// compile: g++ piratesgold3.cpp
// run: ./a.out
// Uses Card and Deck Classes

#include <iostream>
#include <iomanip>
#include <cstdlib>  // for random num generator
#include <ctime>    // for time to seed random num generator
#include "cardclass.cpp"  // Card, Deck types and classes

using namespace std;

// ----- Game Function Prototypes

//---------------------------------------------------------------------------

void PlayPiratesGold (/* in */ DeckType deck);



// -----  Main Function

//---------------------------------------------------------------------------

int main()
{
    DeckType deck;  // A deck of cards for our game

    srand(time(0));    // "Turn on" the random number generator

    deck.Shuffle();   // Shuffle the deck

    PlayPiratesGold (deck);

    return 0;
}


//--------------------------------------------------------------------------
// PlayPiratesGold plays a modified version of Solitaire, called Pirate's Gold, in
//   which the deck is shuffled and eight cards are drawn from the deck and placed on the
//   "table" face up. The player then searches for two matching(face value) cards, at which
//   time two cards are drawn from the deck and placed on top of the matching cards. This process
//   is continued until either all of the cards have been used up, in which the game is won, or when 
//   there are no longer any matching pairs, in which the game is lost.  
//--------------------------------------------------------------------------
// Accepts:  the shuffled deck
// Returns:  Eight Cards
//--------------------------------------------------------------------------

void PlayPiratesGold (DeckType deck)
{

    // local type definition for a card hand

    typedef CardType HandType[7];    // local variables

    HandType hand;   // One hand of cards on the table

    int
	round,		//counter for progressing through the rounds
	cardscore,	//counter for the number of cards drawn so far
	ii,		//counter for progressing through the cards on the table
	j,		//counter for progressing through the cards on the table in the hopes of finding a matching pair
	i;              // counter for progressing through rounds, as well as for counting the first eight cards

    bool 
	complete;	//true/false statement used for whether or not to print the cards
			 //on the table
 
    // Deal eight cards
    for (i = 0; i < 8; i++)
    {
	hand[i] = deck.DrawCard();
    }
    complete = true;
    cardscore =0;    
    cout << "Original Cards on Table\n-----------------------\n";
    hand[0].Print();
    cout << "\t"; 
    hand[1].Print();
    cout << "\t";
    hand[2].Print();
    cout << "\t";
    hand[3].Print();
    cout << "\n";
    hand[4].Print();
    cout << "\t";
    hand[5].Print();
    cout << "\t";
    hand[6].Print();
    cout << "\t";
    hand[7].Print();
    cout << "\n\n";	//Prints the first eight cards drawn from the deck

    cout << "Table After Each Round of Game\n------------------------------\n";
    cardscore = 8;
    round = 1;
for(i=0; i< (DECKSIZE-8)/2; i++)
{ 
  for (ii=0; ii<8; ii++)
  {    
	for (j=ii+1; j<8; j++) //the ii and j for loops go through each possible combination of cards...
	{			//...until a match is found
	     	if(hand[ii].EqualFace(hand[j]))
		{
		   cardscore=cardscore+2; //counts the number of cards that have been drawn from the deck so far
		   hand[ii]=deck.DrawCard(); //draws a new card from the deck
		   hand[j]=deck.DrawCard();  //draws a new card from the deck
		   complete=true;
		   ii=8;	//when a match is found, it prints the results of this round,
				  //ends the round,
				   //and then moves on to the next round
		}
		else
		{
			complete=false; //if a match is not found, no statement is printed,...
					  //...and it moves on to next pair of cards in the combination
		}
		if (complete==true)
		{ //If a match was found, 
        	cout << "\nRound " << round << "\n\n";
        	hand[0].Print();
        	cout << "\t";
        	hand[1].Print();
        	cout << "\t";
        	hand[2].Print();
        	cout << "\t";
        	hand[3].Print();
        	cout << "\n";  
        	hand[4].Print();
        	cout << "\t";
        	hand[5].Print();
        	cout << "\t";
        	hand[6].Print();
        	cout << "\t";
        	hand[7].Print();
        	cout << "\n\n";
		round = round + 1;
		}
		else
		{
		cout << " ";
		}
	}	
	}
}
if(cardscore==52)
  {
	cout << "\nCongratulations! You won!\n"; //If all the cards have been drawn from the deck,
						   //the game is won
  }
  else
  {	cout << "\nSorry You lose!\n"; //If not, the game is lost
  }
}

Stv3n404 - 2023