Skip to content

Commit

Permalink
lab01: add comments to graphical blackjack
Browse files Browse the repository at this point in the history
  • Loading branch information
adammw committed Aug 14, 2012
1 parent 22164d2 commit a9a4e8b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@
#include <iostream>
#include "Card.h"

/**
* Card constructor with parameters to initialise which card it represents
* @param r rank
* @param s suit
*/
Card::Card(rank r, suit s) {
_rank = r;
_suit = s;
_faceup = false;
}

/**
* Turn the card over
*/
void Card::turn_over() {
_faceup = !_faceup;
}

/**
* Get a string representation of the card
* @return a string representation of the card
*/
std::string Card::str() {
// Returns asterisks
if (!_faceup)
return "**";

std::ostringstream result;
if (_rank < JACK) {
// Print the number value of the rank for 2-9,
// or use a letter representing the card
if (_rank == ACE) {
result << "A";
} else if (_rank < JACK) {
result << _rank;
} else if (_rank == JACK) {
result << "J";
Expand All @@ -34,6 +51,7 @@ std::string Card::str() {
result << "K";
}

// Append a letter representing the suit
if (_suit == CLUB) {
result << "C";
} else if (_suit == DIAMOND) {
Expand All @@ -44,17 +62,30 @@ std::string Card::str() {
result << "S";
}

// Return a string represntation of the stringstream
return result.str();
}

/**
* Get the rank of the Card object
* @return rank of the card
*/
Card::suit Card::get_suit() {
return _suit;
}

/**
* Get the rank of the Card object
* @return rank of the card
*/
Card::rank Card::get_rank() {
return _rank;
}

/**
* Get if the card is face up or not
* @return true if the Card is face up
*/
bool Card::is_faceup() {
return _faceup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
#ifndef CARD_H_
#define CARD_H_

/**
* Card class represents a card and what the card knows and it can do
*/
class Card {
public:
// Enum for all possible card suits
enum suit {
CLUB,
DIAMOND,
HEART,
SPADE
};

// Enum for all possible card ranks
enum rank {
ACE = 1,
TWO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,49 @@

#include "GraphicalCard.h"

/**
* Constructor for GraphicalCard, initialises local variables and invokes Card constructor
* @param spritesheet The bitmap conatining the Card image
* @param r rank
* @param s suit
*/
GraphicalCard::GraphicalCard(bitmap spritesheet, Card::rank r, Card::suit s) : Card(r,s) {
_spritesheet = spritesheet;
_position.x = 20;
_position.y = 20;
}

/**
* Get the position of the Card
* @return the position
*/
point2d GraphicalCard::get_position() {
return _position;
}

/**
* Set the position of the Card
* @param pos the position
*/
void GraphicalCard::set_position(point2d pos) {
_position = pos;
}

/**
* Checks if the card is at the point
* @param pos the point the check
* @return
*/
bool GraphicalCard::is_at(point2d pos) {
return (pos.x >= _position.x &&
pos.x < _position.x + CARD_WIDTH &&
pos.y >= _position.y &&
pos.y < _position.y + CARD_HEIGHT);
}

/**
* Draws the card to the screen at it's location
*/
void GraphicalCard::draw() {
int x = 2, y = 4;
if (is_faceup()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#define CARD_WIDTH 202.5
#define CARD_HEIGHT 315

/**
* The GraphicalCard class inherits the Card class because it has the same functionality as
* a Card, but it can also get and set it's position, and draw itself to the screen.
*/
class GraphicalCard: public Card {
private:
point2d _position;
Expand Down

0 comments on commit a9a4e8b

Please sign in to comment.