I created the class using two files. Card.h and Card.cpp as far as I know the classes are standard c++. Here is the source for the class.
The Card.h file contains:
Code:
#pragma once
using namespace System::Drawing;
using namespace System::Windows::Forms;
enum Suit { clubs, diamonds, spades, hearts };
class Card
{
public:
Card(void);
~Card(void);
private:
int number; // 2 to 10, jack, queen, king, ace
Suit suit; // clubs, diamonds, hearts, spades
public:
// initialize card
void init(int n, Suit s);
int GetCardNumber(void);
// Return card suit
Suit GetCardSuit(void);
// Display card
void display(Graphics* gobj, ImageList* imageList1, int XPos, int YPos);
};
The Card.cpp file contains:
Code:
#include "StdAfx.h"
Card::Card(void)
: number(0)
{
}
Card::~Card(void)
{
}
// initialize card
void Card::init(int n, Suit s)
{
suit = s;
number=n;
}
// Return card number
int Card::GetCardNumber(void)
{
return number;
}
// Return card suit
Suit Card::GetCardSuit(void)
{
return suit;
}
// // Display card
void Card::display(Graphics* gobj, ImageList* imageList1, int XPos, int YPos)
{
int index = number - 2 + suit * 13;
imageList1->Draw(gobj, XPos, YPos, index);
}
The problem seems to be when declaring arrays added to the forms.h code that gets generated by Visual Studio.
When I am using the Card class in the paint method of the forms.h class this way:
Code:
Graphics* gr = CreateGraphics();
Card mycard;
mycard.init(11,hearts);
mycard.display(gr,imageList1,500,500);
it works beautifully. But when I try to use an array for the class nothing seems to work as expected.
the following declaration only creates an array of one element:
Code:
static Card* deck = new Card[CardsInDeck];
where CardsInDeck is 52.
I have no clue as to what is going on. Does anyone have an idea that I can try?