You are here:

C++/multiplayer card game

Advertisement


Question
Hi,

First of all I'd better admit, I'm very new to C++, at most I've written some custom functions & scripts for RPG games.

I'm now starting to learn C++ properly, and for my first 'decent' project I want to write a multiplayer card game..

The game uses one set of playing cards, with a 'pick-up' pile, a discard pile, and at least two player piles.

What would you recommend as the best way of keeping track of where all the cards are, ie. so that all the cards (in the various piles) are in the correct positions in their pile?

Also, once I (eventually) get it working one one pc, what's the best way to send 'player moves' over an intranet/internet connection?

I apologise for writing to you so early in the process, but I'm still trying to map out the programmes' logic at this point, and your advice would really help.

With thanks,

Al

Answer
Al, Thank you for your question.

I would represent the data in two parallel ways: in the Graphical User Interface, which would display the cards and piles on the screen upon receipt of a Windows WM_PAINT message and after any user action, and internal data structures, which would represent the data in a form suitable for easy manipulation by the program. Depending on the complexity of the game, it may be possible to merge these two representations into one.

You indicate that there would be 52 cards and three piles, so I might use three fixed-length lists in memory to hold the card numbers (and whether faceup or facedown) for each pile. List operations would allow cards to be moved between piles. Painting the display would be done by enumerating the items in each list and painting the appropriate preconstructed card bitmap at the appropriate position in the client area of the game window.

For communication over the Internet, I would probably use Winsock, which is a library of functions used to send text and other messages between a "client" and "server" computer (the client makes the first call across the Internet to the other computer).

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.