- The whole code and project is in the zip file!
- Here there is only a description.
-
- Classes
- I used 2 classes for the MFC dialog boxes and classes for the lower level C++/STL engine. CDeck for the deck of cards, CGameCard for the 40 cards, CPlayer for the 2 players you and your Pc and GameNapoletano for the whole game.
- Some code
- I used a function to load .jpg and .bmp from files and to render them to the DC: // This function loads a file into an IStream.
- void myUtilities::LoadPictureFile(LPCTSTR szFile, LPPICTURE &gpPic)
-
- And this function uses the OLE technology To map cards picture with the key code that identify the card I used the std::map. For each card I built a key code using its value and its family (there are 40 cards, 10 cards and 4 families) typedef std::map<int, LPPICTURE, std::less > PicCardType;
-
- So in the OnPaint function of the main dialog box I show all the current cards in the game, using a std::vector, where I pushed the pointer to the picture card: std::vector<LPPICTURE>
-
- Before that, every random card, taken from the deck, has to be found in the map already built, by its key code. // take the idCard from the current card
- int idCard = card.GetIdCard();
- // with the idCard we can find the iterator to the picture by the map
- m_itMyCard = m_CardMap.find(idCard);
-
- When the 40 cards are all gone, I have to reshuffle the deck, but I have not to use the card still on the table! So I have to use another deck where I copied all the cards used and reshuffle that one...
- Conclusion
- I wrote this code for hobby. Next step will be a poker card game, hopefully reusing the same structure and inheriting from the same classes... Feel free to suggest me your code, and your opinion is always appreciated. Tell me where I have to change, where the code really sucks and what you would do instead.
-
- Thank you
-
The whole code and project is in the zip file!
Here there is only a description.
Classes
I used 2 classes for the MFC dialog boxes and classes for the lower level C++/STL engine. CDeck for the deck of cards, CGameCard for the 40 cards, CPlayer for the 2 players you and your Pc and GameNapoletano for the whole game.
Some code
I used a function to load .jpg and .bmp from files and to render them to the DC: // This function loads a file into an IStream.
void myUtilities::LoadPictureFile(LPCTSTR szFile, LPPICTURE &gpPic)
And this function uses the OLE technology To map cards picture with the key code that identify the card I used the std::map. For each card I built a key code using its value and its family (there are 40 cards, 10 cards and 4 families) typedef std::map<int, LPPICTURE, std::less > PicCardType;
So in the OnPaint function of the main dialog box I show all the current cards in the game, using a std::vector, where I pushed the pointer to the picture card: std::vector<LPPICTURE>
Before that, every random card, taken from the deck, has to be found in the map already built, by its key code. // take the idCard from the current card
int idCard = card.GetIdCard();
// with the idCard we can find the iterator to the picture by the map
m_itMyCard = m_CardMap.find(idCard);
When the 40 cards are all gone, I have to reshuffle the deck, but I have not to use the card still on the table! So I have to use another deck where I copied all the cards used and reshuffle that one...
Conclusion
I wrote this code for hobby. Next step will be a poker card game, hopefully reusing the same structure and inheriting from the same classes... Feel free to suggest me your code, and your opinion is always appreciated. Tell me where I have to change, where the code really sucks and what you would do instead.
Thank you