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
|
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
/*
Cards are compared by rank first, and only then by suit.
standard ranking of suits followed in the game.
Reverse alphabetical order: clubs (lowest), followed by diamonds, hearts, and spades (highest).
For example,the ace of clubs ranks higher than any king, but lower than the ace of diamonds.
*/
/* Random No generation:
Here we need a random no generation between 2 and 13 i.e 13 no's which are >=2
2,3,4,5,6,7,8,9,10,
11 - Jack
12 - Queen
13 - King
14 - Ace
For suits: Here's the ranking:
1 - Clubs
2 - Diamonds
3 - Hearts
4 - Ace
*/
using namespace std;
class HighCard
{
public:
HighCard(){}
~HighCard(){}
int Suit;
int FaceValue;
void DrawCard() //No parameters necessary, use for first draw
{
Suit = rand() % 4 + 1;
FaceValue = rand() % 13 + 2;
}
void DrawCard(HighCard ComparisonCard) //pass card that was drawn, use for second draw for when there's only 1 deck
{
Suit = rand() % 4 + 1;
FaceValue = rand() % 13 + 2;
while (Suit == ComparisonCard.Suit && FaceValue == ComparisonCard.FaceValue) //If card drawn is card already drawn, redraw
{
Suit = rand() % 4 + 1;
FaceValue = rand() % 13 + 2;
}
}
int CompareSize(HighCard ComparisonCard) //Returns 1 if the card calling the function is bigger, returns 0 if the other card is bigger, returns 2 if they're the same size
{
if (FaceValue>ComparisonCard.FaceValue)
{
return 1; //card calling the function is bigger
}
if (FaceValue<ComparisonCard.FaceValue)
{
return 0; //Card that is being compared to is bigger
}
if (FaceValue==ComparisonCard.FaceValue) //If face values are equal, check suit
{
if (Suit>ComparisonCard.Suit)
{
return 1; //Suit of our card is bigger than comparison card
}
if (Suit<ComparisonCard.Suit)
{
return 0; //Suit of card being compared is bigger
}
if (Suit==ComparisonCard.Suit)
{
return 2; //Suits are the same
}
}
}
};
int main()
{
HighCard card1;
HighCard card2;
card1.DrawCard();
card2.DrawCard(card1);
int ReturnValue = card1.CompareSize(card2);
//If returnvalue is 0 that means that card2>card1
//If returnvalue is 1 that means that card1>card2
//If return value is 2, that means they're equal
if (ReturnValue==0)
{
cout << "Card 2 is bigger than card 1." << endl;
cout << "Card 1 Suit:" << card1.Suit << endl;
cout << "Card 1 FaceValue:" << card1.FaceValue << endl;
cout << "Card 2 Suit:" << card2.Suit << endl;
cout << "Card 2 FaceValue:" << card2.FaceValue << endl;
}
if (ReturnValue==1)
{
cout << "Card 1 is bigger than card 2." << endl;
cout << "Card 1 Suit:" << card1.Suit << endl;
cout << "Card 1 FaceValue:" << card1.FaceValue << endl;
cout << "Card 2 Suit:" << card2.Suit << endl;
cout << "Card 2 FaceValue:" << card2.FaceValue << endl;
}
if (ReturnValue==0)
{
cout << "Card 2 is equal to card 1." << endl;
cout << "Card 1 Suit:" << card1.Suit << endl;
cout << "Card 1 FaceValue:" << card1.FaceValue << endl;
cout << "Card 2 Suit:" << card2.Suit << endl;
cout << "Card 2 FaceValue:" << card2.FaceValue << endl;
}
return 0;
}
|