1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#include<cstdlib>
#include<cmath>
#include<iomanip>
#include<string>
#include<iostream>
#include<fstream>
#include<ctime>
#include<vector>
using namespace std;
//constant
const int MAX = 52;
//prototypes
void rules();
void shuffle();
void yourdeck();
void theirdeck();
//class
class card {
public:
char value;
string suit;
void printcard()
{
cout << value << " of " << suit;
}
};
card deck[MAX], temp;
int main()
{
//variables
srand(time(NULL));
char value[]{ 'A','2','3','4','5','6','7','8','9','X','J','Q','K' };
string suit[]{ "Hearts","Diamonds","Clubs","Spades" };
int i, j, l=0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 13; j++)
{
deck[l].value = value[j];
deck[l].suit = suit[i];
l++;
}
}
//input
cout << "Welcome to the game of WAR!";
cout << "\n";
rules();
//calculations
shuffle();
//output
cout << "\n";
cout << "Your card \t Their card\n";
theirdeck();
yourdeck();
return 0;
}
//function definitions
void rules()
{
int ch;
cout << "Would you like to hear the rules? Press 1 for yes or 2 for no: ";
cin >> ch;
if (ch == 1)
{
cout << "\n";
cout << "You will be playing the Computer, each of you will be given 26 cards." << endl;
cout << "You will both throw down one card, whoever lower card will collect both cards and put them in their decks.\n";
cout << "If you both have the same value card then you will commence the game of war!\n";
cout << "Both players will lay down 3 cards face down and then flip a card.\n";
cout << "Whoever has the lower card loses and collects all the cards in the pile!\n";
cout << "The first person with zero cards left is declared the winner!\n";
cout << "Goodluck!\n";
cout << "\n";
}
else
{
cout << "no rules" << endl;
}
}
void shuffle()
{
int n, m;
for (n = 0; n < 52; n++)
{
m = rand() % 52;
temp = deck[n];
deck[n] = deck[m];
deck[m] = temp;
}
}
void yourdeck()
{
int k;
for (k = 0; k < 25; k++)
{
deck[k].printcard();
cout << "\n";
}
}
void theirdeck()
{
int k;
for (k = 26; k < 52; k++)
{
deck[k].printcard();
cout << endl;
}
}
|