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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/grpatillo/pirategold.cpp
/*	File Name:	pirategold.cpp
	Author:		R.P. Patillo
	Instructor:	Dr. Ames
	Due Date:	Sept. 4, 2008
	Complilation:	g++ pirategold.cpp -o pirategold.out
	Execution:	./pirategold.out
*/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include "cardclass.cpp"

using namespace std;

//--------------------------------------
//--- PirateGold function Prototype ---
//--------------------------------------

void PlayPirateGold (DeckType deck);

const int GAMETABLE = 8;

int main()
{
	DeckType deck;
	
	srand(time(0));
	
	deck.Shuffle();
	deck.Shuffle();
	deck.Shuffle();

	PlayPirateGold (deck);
	
	return 0;
}

//--------------------------------------------------
void PlayPirateGold (DeckType deck)
{

//------------------------------------
//--- Defining gametable of cards ---
//------------------------------------

	typedef CardType HandType[GAMETABLE];

	HandType card;

	int gameround, i, j;
	bool cardmatch;

//-----------------------------------------
//--- Printing original table of cards ---
//-----------------------------------------

	for (i = 0; i < GAMETABLE; i++)
	{  
	    card[i] = deck.DrawCard();
	}

	gameround = 0;

	cout << "\nOriginal Cards on Table" << endl;
	cout << "-----------------------\n" << endl;

	for (i = 0; i < GAMETABLE; i++)
	{ 
	    if (i == 4)
		cout << "\n";  
	    card[i].Print();
	    cout << "   \t";
	}

//-------------------------------------------------------------------------
//--- Beginning Pirategold game and sorting through cards to find match---
//-------------------------------------------------------------------------

	cout << "\n\nTable After Each Round of Game" << endl;
	cout << "------------------------------" << endl;


//---------------------------------------------------------
//--- Jumpstarts the loop by setting cardmatch = true; ---
//--- Loop sorts through cardsd to find a match-----------
//---------------------------------------------------------

	cardmatch = true;
	while (cardmatch && !deck.IsEmpty())
	{
	    i = 0;
	    cardmatch = false;
	    while (i < GAMETABLE && !cardmatch)
	    {
		j = i + 1;
		while (j < GAMETABLE && !cardmatch)
		{
		    if (card[i].EqualFace(card[j]))
		    {
			card[i] = deck.DrawCard();
			i = j;
		    	card[i] = deck.DrawCard();
		    	gameround++;   
		    	cout << "\n\nRound "  << gameround << "\n" << endl;

		        for (i=0; i<8; i++)
		        {
			    if (i == 4)
				cout << "\n";
			    card[i].Print();
			    cout << "   \t";
		        }
			cardmatch = true;
		    }
		    
		    else 
			j++;
		}

		i++;	 		    	    
	         
	    }
	}

//------------------------------------------------------
//--- if deck is empty, you win... if not, you lose ---
//------------------------------------------------------

        if (deck.IsEmpty() == true)
        {
            cout << "\n**************************************" << endl;
            cout << "****   Congrats!!!! You Win!!!!   ****" << endl;
            cout << "**************************************" << endl;
	}

	if (deck.IsEmpty() == false)
	{
	    cout << "\n**************************************" << endl;
	    cout << "*****    Sorry!!! You Lose!!!    *****" << endl;
	    cout << "**************************************" << endl;
	}	
}


Stv3n404 - 2023