Accueil > > > JEU DE CARTES ITALIENNES EN VISUAL C++
JEU DE CARTES ITALIENNES EN VISUAL C++
Information sur la source
Description
This article present a simple game card, programmed with MFC, for the graphics and the user feedback, and at lower level I used the STL of C++ to manage the classes for the deck, the players, the game. The same low level structure, could be reused for a different future game (Poker? Bridge...is too difficult I guess!) I used a dialog based application in the MFC wizard. Description The italian game card "Sette e mezzo" or "Seven and half" is a tipical Christmas game. You have to bet your "virtual" dollars and then take a card from the deck until you feel that your points are enough and under 7 and half that is the maximum allowed point. Then is the Pc's turn to play and it will take cards until it will arrive over your points or until it will loose, because over 7 and half!
Source
- 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
Conclusion
Mauro (Maurus) Mindoli email: mindolimauro@rocketmail.com
Hobbye s: Soccer, Chess, Programming, Progressive Rock, Video Games
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|