Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.117.105.230
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/pirategold.cpp
// Pirate's Gold - a simple card game
//
// September 2008
// Justin McCreary

// 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;
}


//--------------------------------------------------------------------------
// PlayWarGame plays a modified version of War, making one pass through
//   the deck of cards.  Each player places next card in hand on table.
//   Player whose card has highest face value gets 2 points.  In case of
//   face value tie, suits are compared according to Bridge hierarchy.
//   After all cards are played, player with highest score wins.
//--------------------------------------------------------------------------
// Accepts:  the shuffled deck
// Returns:  nothing
//--------------------------------------------------------------------------

void PlayPiratesGold (DeckType deck)
{

    // local type definition for a card hand

    typedef CardType TableType;

    // local variables
	int
	tcard1, tcard2, tcard3, tcard4, tcard5, tcard6, tcard7, 
tcard8, 
	tcardscore,     // score counters
	i;              // counter for progressing through hands

    // Deal one hand

	tcard1 = deck.DrawCard();
	tcard2 = deck.DrawCard();
	tcard3 = deck.DrawCard();
	tcard4 = deck.DrawCard();
	tcard5 = deck.DrawCard();
	tcard6 = deck.DrawCard();
	tcard7 = deck.DrawCard();
	tcard8 = deck.DrawCard();

    // Play the game

    //     Output headings and initialize scores

    tcardscore = 0;
    //hand2score = 0;

    cout << "Orginal Cards on Table\n\n";
    //cout << "Player 1\t\tPlayer 2\t\tWinner\n\n";
	tcard1.Print();
	cout << "	/t";
	tcard2.Print();
	cout << "	/t";
	tcard3.Print();
	cout << "	/t";
	tcard4.Print();
	cout << "/n";
	tcard5.Print();
	cout << "	/t";
	tcard6.Print();
	cout << "	/t";
	tcard7.Print();
	cout << "	/t";
	tcard8.Print();
	cout << "/n/n";	
    //     Loop through the hands of cards
	tcardscore = 8;
	cout << "Table After Each Round of Game\n\n";
    for (i = 0; i < 22, i++)
    {
	// let's see who has the "highest" card

	if (tcard1.EqualFace(tcard2))   // matching face values ...
	{
		tcardscore = tcardscore + 2;
		tcard1 = deck.DrawCard();
		tcard2 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
        	tcard1.Print();
        	cout << "       /t";
        	tcard2.Print();
        	cout << "       /t";
        	tcard3.Print();
        	cout << "       /t";
        	tcard4.Print();
        	cout << "/n";
        	tcard5.Print();
        	cout << "       /t";
        	tcard6.Print();
        	cout << "       /t";
        	tcard7.Print();
        	cout << "       /t";
        	tcard8.Print();
      		cout << "\n\n";
	}
	elseif (tcard1.EqualFace(tcard3))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard3 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

	}
	elseif (tcard1.EqualFace(tcard4))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard4 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard1.EqualFace(tcard5))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard5 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard1.EqualFace(tcard6))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard6 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard1.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard1.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard1 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard3))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard3 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard4))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard4 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard5))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard5 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard6))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard6 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard2.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard2 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard3.EqualFace(tcard4))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard3 = deck.DrawCard();
                tcard4 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard3.EqualFace(tcard5))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard3 = deck.DrawCard();
                tcard5 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard3.EqualFace(tcard6))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard3 = deck.DrawCard();
                tcard6 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard3.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard3 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard3.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard3 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard4.EqualFace(tcard5))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard4 = deck.DrawCard();
                tcard5 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard4.EqualFace(tcard6))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard4 = deck.DrawCard();
                tcard6 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard4.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard4 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard4.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard4 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard5.EqualFace(tcard6))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard5 = deck.DrawCard();
                tcard6 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard5.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard5 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard5.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard5 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard6.EqualFace(tcard7))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard6 = deck.DrawCard();
                tcard7 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard6.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard6 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	elseif (tcard7.EqualFace(tcard8))   // matching face values ...
        {
                tcardscore = tcardscore + 2;
                tcard7 = deck.DrawCard();
                tcard8 = deck.DrawCard();
		cout << "Round " << i+1 << "\n\n";
                tcard1.Print();
                cout << "       /t";
                tcard2.Print();
                cout << "       /t";
                tcard3.Print();
                cout << "       /t";
                tcard4.Print();
                cout << "/n";
                tcard5.Print();
                cout << "       /t";
                tcard6.Print();
                cout << "       /t";
                tcard7.Print();
                cout << "       /t";
                tcard8.Print();
                cout << "\n\n";

        }
	else
	{
		i = i + 22;
	}
    }

    // Let's see if the game was won!


    if (tcardscore<52)
	cout << "Sorry! You Lose!";
    else
	cout << "Congratulations! You Won!";
}

Stv3n404 - 2023