I have code to my blackjack project. I am stuck right now and was wanting to see if the code I have now is correct, what I should do next and information dealing with what to do in main.
Cards can be displayed in a shorthand. For example 2-S for the 2 of spades card, K-D for the king of diamonds. To help the user display the total for his current hand every time a decision is required. In our game the dealer will always stand on values of 17 or more. For simplicity in our game aces will always be worth 11 points. We will not implement betting, splitting or more complicated rules.
You will need to define and implement a base class (does not have to be abstract) called Card. This class should store the cards name, suit, and point value. There should be functions for getting the name, suit, and value. There should be a class for each suit (Spade, Club, Diamond, Heart) that inherits from the Card class. There should a class for each card value (2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace) that inherits from the suit classes.
There should be a Deck class that includes 52 Card objects. Other classes can be added to fit your design.
So I have created a class for every card, all 4 suits, Card and Deck. Ex. aceOfSpades.h , twoOfClubs.h and they all inherit from my from there suit Class and the suits inherit from Card. In each .h file of each card I have assigned the number for it already.
Ex.
aceOfClubs::aceOfClubs()
{
number = 11;
}
Here is my Card class:
#include "Card.h"
Card::~Card() {}
Card::Card(int SUIT, int num)
{
number=num;
suit=SUIT;
}
int Card::getValue(const)
{
return number;
}
int Card::getSuit()
{
return suit;
}
void Card::setValue(int x)
{
number = x;
}
void Card::setSuit(int x)
{
suit = x;
}
void Card::print()
{
cout << "Suit:" << suit << "Number:" << number << endl;
}
And my Deck class..I have not added all 52 card objects as I am stuck on knowing how to do it. Instead I used enum in the main.cpp for each but I am not sure if I am supposed to do that.
#include "Card.h"
Card::~Card() {}
Card::Card(int SUIT, int num)
{
number=num;
suit=SUIT;
}
int Card::getValue(const)
{
return number;
}
int Card::getSuit()
{
return suit;
}
void Card::setValue(int x)
{
number = x;
}
void Card::setSuit(int x)
{
suit = x;
}
void Card::print()
{
cout << "Suit:" << suit << "Number:" << number << endl;
}
And this is all I have in main.cpp
#include <iostream>
#include <ctime>
using namespace std;
void shuffleDeck()
{
for (int i=0;i<52; i++)
{
swap Deck, Deck[RAND_MAX % 52];
}
}
int main()
{
enum Cards { one=1, two=2, three=3, four=4, five=5, six=6, seven=7, eight=8, nine=9, ten=10, Jack=10, Queen=10, King=10, Ace=11 }
enum Suits { Clubs, Diamonds, Hearts, Spades }
char input;
cout << "Do you want to play again (Y/N) ? " ;
cin >> input;
if ((input == "y") || (input == "Y"))
{
shuffleDeck();
break;
}
if ((input == "n") || (input =="N")
{
break;
}
return 0;
}