Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC

Italian card game: Seven and Half ver. 2.0

Rate me:
Please Sign up or sign in to vote.
4.50/5 (18 votes)
26 Apr 2012GPL33 min read 154.9K   3K   37   32
This is an Italian game card, programmed with MFC and C++ STL, enjoy!

Sample Image - Italiangamecard.gif

Introduction

This article presents a simple game card, programmed with MFC. For graphics and user feedback, and at a lower level, I used STL of C++ to manage the classes for the deck, the players, and 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. I've updated the game to version 2.0 because I added some other features. The game is a freeware and a full version is available with all the source code in C++ and MFC.

Description

The Italian game card "Sette e mezzo" or "Seven and half" is a typical 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 seven and half, that is the maximum allowed point. Then it is the PC's turn to play and it will take cards until it will arrive over your points or until it will lose, because over seven and half! The rules are explained in the game with the Help dialog box. Your first card is hidden so the PC can only count the points by the other cards and you can also use only one card to try to beat the PC that will "learn" from your style of playing!

Classes

I used two 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 two 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:

C++
// This function loads a file into an IStream.
void myUtilities::LoadPictureFile(LPCTSTR szFile, LPPICTURE &gpPic)

And this function uses the OLE technology.

To map a card's picture with the key code that identifies the card, I used 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).

C++
typedef std::map<int, LPPICTURE, std::less<int> > 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:

C++
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.

C++
// 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 cannot 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...

New features for version 2.0

I added some features suggested to me by many players: first of all, the game needed to follow the official rules of the game, so I added the jolly card that is the king of gold, and I added to the first hidden card to the player, so the PC now cannot count all the points and it is more difficult to beat us! There are sounds for every action and it is possible to disable them. Bets are only allowed after we get the hidden card.

Conclusion

I wrote this code as a hobby. The next step will be a poker card game, hopefully reusing the same structure and inheriting from the same classes... Feel free to suggest 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.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Italy Italy
I am born in 1965 in Ascoli Piceno (Italy).

My email is maurus@rocketmail.com

HIGHER EDUCATION:
Degree in Computer Science with a mark of 95/110,
University of Pisa in July 1992.
KNOWLEDGE OF FOREIGN LANGUAGES:
Mother tongue Italian.
Very good knowledge of both English and French.

COMPUTER KNOWLEDGE:
Operating systems:
Windows, Windows CE.
real time systems on micro.

Programming languages:
C, C++, VisualC++, Pascal, Basic, Coral, Assembly, Win32.
Libraries:
Qt, STL, Roguewave, OpenGL, MFC.
Tools
Cycle V, Design Patterns
Frameworks:
Visual Studio, DevC++, Qt Creator, Codewarrior
Micro: Mitsubishi, Texas DSP, Intel.

WORKING EXPERIENCES:
From april 1994 to march 2000 I worked in Gem Elettronica (http://www.gemrad.com) in San Benedetto del Tronto (Italy), a company that produce real time systems, naval radars, geographical position system (G.P.S.), cartographical consoles in civil and military environment (Custom Officers, Italian Militar Navy, Carabinieri).
I developed software in C/C++ inside a team work environment for international naval radar sites. I cooperated with other programmers of the Lockheed Martin Company, the Rohde & Schwarze and the Alenia Marconi Systems.
I mainly worked with real time systems, localisation radio and GPS systems.

From march 2000 to july 2001 I worked in Ericsson Cables (http://www.ericsson.com/networktechnologies) in Sundbyberg (Sweden).
I developed software for fusion splicers in a Windows CE environment in C++, Win32, MFC.
Video analyses, micro motor motion and micro cameras.

From August 2001 to February 2003
I worked in France, Paris developing in C++ under Windows, for a French company that produced software to share informations.

From March 2003
I am actually working in my first company Gem Elettronica.
I also develop Vessel Traffic Systems and Laser Gyrosteps interfaces.
My current job is to manage projects with naval and river radars.

We used Qt, Win32, MFC, C++, STL, DLL, OpenGL

Comments and Discussions

 
QuestionGreat Game! Great Coding! Pin
Member 1098426831-Jul-14 11:41
Member 1098426831-Jul-14 11:41 
AnswerRe: Great Game! Great Coding! Pin
Maurus24-Sep-14 5:47
Maurus24-Sep-14 5:47 
General7.5 ROTFL Pin
Aoi Karasu 12-Jan-10 3:11
professional Aoi Karasu 12-Jan-10 3:11 
GeneralNice article! Pin
ucc80111-May-05 22:51
ucc80111-May-05 22:51 
GeneralVery cultural article Pin
Anthony_Yio1-Dec-03 17:12
Anthony_Yio1-Dec-03 17:12 
GeneralRe: Very cultural article Pin
Maurus15-Mar-04 2:42
Maurus15-Mar-04 2:42 
GeneralC++ MFC program help arrtillery Pin
Anonymous16-Feb-03 11:17
Anonymous16-Feb-03 11:17 
GeneralRe: C++ MFC program help arrtillery Pin
Maurus16-Feb-03 11:42
Maurus16-Feb-03 11:42 
General7 e mezzo ? NOO ! 7 y media !!! Pin
Braulio Dez11-Feb-03 21:10
Braulio Dez11-Feb-03 21:10 
GeneralRe: 7 e mezzo ? NOO ! 7 y media !!! Pin
Maurus11-Feb-03 22:22
Maurus11-Feb-03 22:22 
GeneralDon´t you... Pin
MarcosEdu9-Feb-03 23:11
MarcosEdu9-Feb-03 23:11 
GeneralRe: Don´t you... Pin
Maurus9-Feb-03 23:38
Maurus9-Feb-03 23:38 
GeneralRe: Don´t you... Pin
MarcosEdu10-Feb-03 7:29
MarcosEdu10-Feb-03 7:29 
GeneralRe: Don´t you... Pin
Maurus10-Feb-03 10:01
Maurus10-Feb-03 10:01 
GeneralSCOPA!!! Pin
Roman Nurik27-Jan-03 7:39
Roman Nurik27-Jan-03 7:39 
GeneralRe: SCOPA!!! Pin
Maurus27-Jan-03 8:33
Maurus27-Jan-03 8:33 
GeneralFeel free to add a comment Pin
Maurus26-Jan-03 9:27
Maurus26-Jan-03 9:27 
GeneralRe: Feel free to add a comment Pin
Goran Mitrovic26-Jan-03 13:22
Goran Mitrovic26-Jan-03 13:22 
GeneralRe: Feel free to add a comment Pin
Maurus26-Jan-03 22:29
Maurus26-Jan-03 22:29 
GeneralRe: Feel free to add a comment Pin
Anonymous26-Jan-03 22:05
Anonymous26-Jan-03 22:05 
GeneralRe: Feel free to add a comment Pin
Maurus26-Jan-03 22:34
Maurus26-Jan-03 22:34 
GeneralRe: Feel free to add a comment Pin
Chopper26-Jan-03 23:09
Chopper26-Jan-03 23:09 
GeneralRe: Feel free to add a comment Pin
Maurus26-Jan-03 23:14
Maurus26-Jan-03 23:14 
GeneralRe: Feel free to add a comment Pin
Chopper26-Jan-03 23:23
Chopper26-Jan-03 23:23 
That was russian, but nevermind, just write in english next timeBig Grin | :-D


Ultimate all-in-one XP-Style UI multiplatform solution: Tooltips, XP Menus, Hyperlinks, Drawing Graphics and formatted documents, plus powerful binary resource reuse. All Free 100%, visit www.tooltips.net now. The most powerful integrate UI library for developers in VC++, C#, Java, VB, Delphi, Borland C++, Borland C++ Builder, as well as any COM-compatible platform; Unified approach, cross-language OS, full .NET integration.
GeneralRe: Feel free to add a comment Pin
Maurus26-Jan-03 23:28
Maurus26-Jan-03 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.