Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.220.200.197
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 (0755) :  /home/slcebula/cs311/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/slcebula/cs311/war.cpp
//Name:         Lee Cebula
//Professor:    Professor Ames
//Title:        war.cpp
//Due Date:     8/28/08
//Compiling:    g++ war.cpp
//Execution:    ./a.out
//Goal:         Create the basic classes to simulate a game of war.

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

using namespace std;

void PlayWarGame (DeckType deck);

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

void PlayWarGame (DeckType deck)
{
	typedef CardType HandType[DECKSIZE/2];

	HandType hand1, hand2;
	int hand1score, hand2score, i;

	// Deal two hands
	for (i = 0; i < DECKSIZE/2; i++)
	{
		hand1[i] = deck.DrawCard();
		hand2[i] = deck.DrawCard();
	}

	//Play the game
	hand1score = 0;
	hand2score = 0;

	cout << "The Game of War\n\n";
	cout << "Player 1\t\t\tPlayer 2\t\t\tWinner\n\n";

	// Loop through the hands of cards
	for(i = 0; i < DECKSIZE/2; i++)
	{
		hand1[i].Print();
		cout << "	\t";
		hand2[i].Print();
		cout << "	\t";

		if (hand1[i].GreaterFace(hand2[i]))
		{
			hand1score += 2;
			cout << "Player 1\n";
		}
		else if (hand1[i].EqualFace(hand2[i]))
			if (hand1[i].GreaterSuit(hand2[i]))
			{
				hand1score += 2;
				cout << "Player 1\n";
			}
			else
			{
				hand2score += 2;
				cout << "Player 2\n";
			}
		else
		{
			hand2score += 2;
			cout << "Player 2\n";
		}
	}

	// Who is the winner?

	cout << "\n----------------------------------------------";
	cout << "\nFinal Scores\n";
	cout << "Player 1: " << hand1score;
	cout << "\nPlayer 2: " << hand2score;
	cout << "\n\nAnd The Winner is ... ";

	if (hand1score > hand2score)
		cout << "Player 1!\n";
	else if (hand2score > hand1score)
		cout << "Player 2!\n";
	else
		cout << "IT'S A TIE!\n";
	cout << "----------------------------------------------\n";

}

Stv3n404 - 2023