DUE: Sun May 22, 11 pm
(10% penalty for late submission, up to 1 day late)
Any changes to this document, typically due to an error on the part of the author, will be logged here.
Collaboration is strongly ENCOURAGED within a programming team, but the program you submit must still represent YOUR OWN original work. Teams should work on the algorithm together, and help debug/test each others code. However, copying code from ANY outside source (any book, current or past students, past solutions, web sites, etc.) is STRICTLY FORBIDDEN. Copy and Paste from another solution, including the solution of a team mate will incur a stiff penalty.
One of the easier categories of games to implement on the computer are card games. With this in mind we are going to implement a card class and a deck class so that we can write a card game.
Just as we could think of the tic-tac-toe cell as a simplified button; we might think of the card as a glorified button. Unlike the tic-tac-toe cell, the card will potentially be moved around the drawing area, hidden at times, flipped over, etc.
A card has both a value, and a suit. The value of the card is one of the following: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K. The suit of the card is either diamonds, spades, hearts, or clubs. For simplicity of implementation, you can assume that a Jack has the value of 11, a Queen has the value of 12, and a King has the value of 13.
When a card is created, it should be hidden and orientated FACEDOWN by default. When a card is shown and is FACEDOWN, the back of the card should be shown. It is up to you to design the back of the card however you see fit, but you are not allowed to leave it blank. When the card is shown and is in a FACEUP orientation, the value and suit of the card should be displayed.
The declaration of the card class is as follows:
//! \class Card
//! \brief A Card from a stardard deck of playing cards.
class Card : public Clickable
{
public:
enum Suit { DIAMOND, SPADE, HEART, CLUB };
enum Orientation { FACEUP, FACEDOWN };
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Constructors and Destructors ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Default constructor for the Card class.
Card();
//! \brief Constructor for the Card class.
//! \param value The face value of the card ( 1 - 13 ).
//! \param suit The suit of the card.
//! \param size The size of the card when it is drawn.
Card( const int value, const Suit suit, const double size );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Accessors ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Get the size of the Card.
//! \return The size of the Card.
double getSize() const;
//! \brief Get the suit of the Card.
//! \return The suit of the Card.
Suit getSuit() const;
//! \brief Get the value of the Card.
//! \return The Value of the Card.
int getValue() const;
//! \brief Get the orientation of the Card.
//! \return The Orientation of the Card.
Orientation getOrientation() const;
//! \brief Draw the Card in the drawing area.
//!
//! A Card which is not shown is not drawn.
//! \return Void.
virtual void draw() const;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Mutators ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Set the size of the Card.
//! \param size The size of the Card.
//! \return Void.
void setSize( const double size );
//! \brief Set the suit of the Card.
//! \param suit The suit of the Card.
//! \return Void.
void setSuit( const Suit suit );
//! \brief Set the value of the Card.
//! \param value The value of the Card ( 1 - 13 ).
//! \return Void.
void setValue( const int value );
//! \brief Set the orientation of the Card.
//! \param orientation The orientation of the Card.
//! \return Void.
void setOrientation( const Orientation orientation );
//! \brief Change the orientation of the card.
//! \return Void.
void flip();
//! \brief Move the card by a displacement.
//! \param x_displace The distance to move the object in the x-direction.
//! \param y_displace The distance to move the object in the y-direction.
//! \return void.
virtual void move( const double x_displace, const double y_displace );
private:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Private Members ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Draw the border of the Card.
//! \return Void.
void drawBorder() const;
//! \brief Draw the face of the Card.
//! \return Void.
void drawFace() const;
//! \brief Draw the back of the Card.
//! \return Void.
void drawBack() const;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Private Data ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private:
Suit suit; //!< The suit of the card.
int value; //!< The face value of the card.
double size; //!< The size of the card in the drawing area.
Orientation orientation; //!< The orientation ( faceup or facedown )
};
As in the previous assignment the public interface of the class is to remain the same; you are allowed to do whatever you wish for the private methods and variables.
The deck is a collection of cards. For this implementation we will implement a standard 52 card deck. There should be a card with every value in every suit.
When a deck is created the cards should be of a size of your choosing and put in a shuffled order. When the deck is reset the cards should again be reshuffled and the deck should be "full". To get a card from the deck, the "top card" of the deck is dealt, and the card underneath becomes the top card. When all cards have been dealt from the deck the deck is empty. The interface of the deck class is as follows:
//! \class Deck
//! \brief A stardard deck of playing cards.
class Deck
{
public:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Constructors and Destructors ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Default constructor for the Deck class.
//!
//! Creates a deck of cards that are already shuffled.
Deck();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Accessors ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Test whether the deck is empty.
//! \return Whether the deck is empty or not.
bool isEmpty() const;
//! \brief Get the size of the cards in the deck.
//! \return The size of the cards in the deck.
double getCardSize() const;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Mutators ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Deal the top card from the deck.
//! \return The card at the top of the deck.
Card dealTopCard();
//! \brief Set the size of the cards in the deck.
//! \param card_size The size of the cards in the deck.
//! return Void.
void setCardSize( const double card_size );
//! \brief Reset the deck to contain all of the cards in a
//! shuffled order.
//! \return Void.
void reset();
//! \brief Shuffle the cards in the deck.
//! \return Void.
void shuffle();
private:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Private Members ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! \brief Fill the Deck with the cards.
//! \return Void.
void fillDeck();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~ Private Data ~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
std::vector<Card> cards; //!< The cards in the deck.
unsigned int top_card_index; //!< The index of the current top card.
double card_size; //!< The size of the cards in the deck.
};
As in the previous assignment the public interface of the class is to remain the same; you are allowed to do whatever you wish for the private methods and variables.
For this assignment a test harness is being provided for you which tests some of the functionality of the card and deck classes. This is not necessarily the program that will be used to test your classes, so be sure that you have implemented all functionalities and that you are reasonably sure that they work correctly.
For this assignment you will implement the 2 classes Card, and Deck. You do not need to modify any other code. The public interface of the two classes may not be altered, however, you can do whatever you wish for the private members and private data. The files in the framework contain the declaration of private members and data that you may wish to use, but are not obligated to.
As in the previous assignment, the object code for previous assignments is provided in the framework. You may use you own solutions if you wish, or compile in the solution object code.
For this assignment a framwork will be provided for you which includes all of the files that are necessary for you to complete the assignment. The files included in the framework are the following:
You may download the framework here. To uncompress the framework archive you should type:
where <framework_file> is the name of the file that you downloaded.
Submit your work electronically to the correct folder on the cs secure server. Don't forget to include the header template at the top of each file that you submit.
For this assignment you will turn in the following files:
You can download a sample program right-clicking and save-as here. You will probably need to change the permissions on assn8_sample so that it is user executable. You can do this with the command:
Only write a small portion of code before checking that it still compiles. This way when you get a syntax error, you can be fairly certain the error is in the part you just wrote.
The points for this assignment will be distributed as follows:
| Points | Feature Description |
|---|---|
| 2 pts | Program compiles( And files represent an attempt at completing the assignment ) |
| 3 pts |
Adherence to the class coding standard -- ( .5 pts ) Program does not use global variables or objects -- ( .5 pts ) Good variable and function names -- ( .5 pts ) Proper indentation and spacing -- ( .5 pts ) Good comments ( including header and function comments ) -- ( .5 pts ) No line wraps -- ( .5 pts ) Other miscellaneous parts of the standard. |
| 1 pts | Front and back of the card are drawn correctly. ( value and suit on the front, and design on the back ) |
| 1 pts | Hide/Show functionality works correctly. ( Remember that hidden things can not be clicked. ) |
| 1 pts | Card can be flipped. ( Recall that clicking on a card which is shown will also cause the card to flip. ) |
| 1 pts | The next card in the deck can be obtained by calling the dealTopCard member function of the deck. |
| 1 pts | The deck contains the correct 52 cards ( no more, no less ) in random order and the deck is empty once all 52 cards have been dealt. The random ordering should be different every time the program is run, as well as every time the deck is reset. |