Need help with Solitaire code

Hi guys, I have been given the task to comment a code for solitaire which is broken into 3-4 header files. I will post each one seperately, and as I learn what each line of the code does, or each important function, I will post the next header file. So let's get started with the "card" header file.
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


#ifndef CARD_H
#define CARD_H

#include <iostream>
#include "HitBox.h"
#include <allegro.h>

class Card {
	int num;			// A = 1, J = 11, Q = 12, K = 13
	std::string suit;	// C, D, H, S
	int x1, y1, x2, y2, w, h;
	BITMAP *cardPic, *backPic;
	HitBox *hit;
public:
	Card (std::string, std::string);
	~Card ();
	void Draw (BITMAP *, bool);
	void SetPos (int, int, int, int);
	void Debug (BITMAP *);
	bool OnMouse ();
	HitBox* Hit ();
	int X ();
	int Y ();
	std::string Suit ();
	int Num ();
};

Card::Card (std::string NUM, std::string SUIT) {
	num = atoi (NUM.c_str ());
	suit = SUIT [0];
	
	std::string filename = NUM + SUIT + ".tga";
	//std::cout << filename << std::endl;
	
	cardPic = load_bitmap (filename.c_str (), NULL);
	backPic = load_bitmap("Back.tga", NULL);
	
	if (!cardPic)
		std::cout << "ERRORERRORERROR!\n";
	
	hit = new HitBox (0, 0, 0, 0);
}

Card::~Card () {
	delete cardPic;
	delete backPic;
	delete hit;
}

HitBox* Card::Hit () {
	return hit;
}

void Card::Draw (BITMAP *bmp, bool UP) {
	if (UP)
		//draw_sprite (cardPic, bmp, x1, y1);
		masked_blit (cardPic, bmp, 0, 0, x1, y1, w, h);
	else
		//draw_sprite (backPic, bmp, x1, y1);
		masked_blit (backPic, bmp, 0, 0, x1, y1, w, h);
}

void Card::SetPos (int X1, int Y1, int X2, int Y2) {
	x1 = X1;
	y1 = Y1;
	if (X2 == -1)
		x2 = x1 + 61;
	else
		x2 = X2;
	
	if (Y2 == -1)
		y2 = y1 + 86;
	else
		y2 = Y2;
	
	w = x2 - x1;
	h = y2 - y1;
	
	hit -> Move (x1, y1, x2, y2);
}

void Card::Debug (BITMAP *bmp) {
	hit -> Draw (bmp);
}

bool Card::OnMouse () {
	return hit -> OnMouse ();
}

int Card::X () {
	return x1;
}

int Card::Y () {
	return y1;
}

std::string Card::Suit () {
	return suit;
}

int Card::Num () {
	return num;
}
#endif 


Can someone please explain to me what each major function or structure is doing?

Thanks in Advance!
Last edited on
1
2
3
4
5
6
7
8
9
10
11
Card (std::string, std::string); // Creates the card given the suit and value
~Card (); // Cleans up memory when a card is destroyed
void Draw (BITMAP *, bool); // Draws the card with a bitmap picture.  It will either draw it in a "front" or "back" stype
void SetPos (int, int, int, int); // Positions the card. Do this before drawing
void Debug (BITMAP *); // Draws the "hit" region.  Probably used for debug only
bool OnMouse (); // returns whether the card was clicked
HitBox* Hit (); // Returns a pointer to a HitBox, whatever that is
int X (); // Returns the x position of the card
int Y (); // Returns the y position of the card
std::string Suit (); // Returns the suit of the card
int Num (); // Returns the value of the card 
Topic archived. No new replies allowed.