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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/rnlink/piratesgold2.cpp
// Pirate's Gold - a simple card game
//
// August 2008
// R Link

// 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 PlayPirateGame (/* 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

    PlayPirateGame (deck);

    return 0;
}


//--------------------------------------------------------------------------
// PlayPirateGame plays a game known as Pirate's Gold, laying out eight
//   cards out of the full deck and looking to see if there are any
//   matching pairs of face value. If there are, the two cards are
//   replaced with two new cards drawn from the deck. If no pairs are
//   present and the deck is not empty, then the player loses the game.
//   Otherwise, the game is played until the deck is empty and the player 
//   wins.
//--------------------------------------------------------------------------
// Accepts:  the shuffled deck
// Returns:  nothing
//--------------------------------------------------------------------------

void PlayPirateGame(DeckType deck)
{
    const int NumCardsonTable = 8;	// constant for the number of cards on the table

    //	local type definition for a card hand (or, in this game, a layout 
    //	of eight cards)

    typedef CardType HandType[NumCardsonTable];

    //	local variable
    HandType layout;	//    the array that will hold the eight cards 
			//    being played

    int 
	i, 		//    counter for progressing through the layout cards
	u,		//    counter for comparing the layout cards
	k;		//    count for printing while in the loop

    bool matchfound = true;		// flag to get out of the while 
					//  loop if no match is found

    //     Output headings

    cout << "\n\n\nThe Game of Pirate's Gold\n\n";
    cout << "Original Cards on Table\n";
    cout << "-------------------------\n\n";

    //     Draw the initial eight cards and display them.

    for (k = 0; k < NumCardsonTable; k++)
    {
        layout[k] = deck.DrawCard();
	cout << k+1 << ". ";
        layout[k].Print();
	if( k == 3 || k == NumCardsonTable)
	        cout << "\n";
	else
		cout << "\t";
    }

    cout << "\n----------------------------------------------------------------------------\n";

    // 	Play the game

    //  While a match is found and the deck is not empty, keep playing the game.
    while(matchfound && !deck.IsEmpty())	
    {
	i = 0;
	matchfound = false;
	while( i < NumCardsonTable && !matchfound)		// look at the first card
	{
	    u = i+1;
	    while( u < NumCardsonTable && !matchfound)		// look at the second card
	    {
	    	if( layout[i].EqualFace(layout[u]))	// Compares the two cards to each other.
	    	{    matchfound = true;			// Match is found, so set the bool true.

		     // Output information of the match to the player/screen

		     cout  << "\nMatch found! Card " << i+1 << " is the same as card " << u+1;
		     cout  << ". So now we'll replace those cards! \nHere's our ";
		     cout  << "new eight-card-layout!\n\n";	

 		     layout[i] = deck.DrawCard();	// If a match is found, the cards are
		     layout[u] = deck.DrawCard();	//  replaced...

 		     for (k = 0; k < NumCardsonTable; k++)	// ...and the new layout printed.
	             {
        	    	cout << k+1 << ". ";
        	    	layout[i].Print();
        	    	if( k == 3 || k == NumCardsonTable)
                	    cout << "\n";
        	        else
                	    cout << "\t";
    		     }
		     cout << "\n\n";
		}
		else
		    u++;				// Move to the next card to compare to i.	
   	    }
	    i++;					// Move to the next card.
	}
    }

    if(!deck.IsEmpty())					// If, at the end of the game, the deck
	cout << "\n I'm sorry, you lose. \n\n";		//  is not empty, the player loses.
    else						//  Otherwise he/she wins.
	cout << "You win!\n\n";

}


Stv3n404 - 2023