An example of a poker online game
I have nothing to do recently, so I have a brainwave. Why not use a program to implement the poker games that I often play? After several days of hard work, I finally finished it, and it was a bit like a QQ landlord. It was tested to run well on the LAN. Because I have not developed games before, nor have I referenced the code in this area, I still suffer some losses and write a design, so the overall structure and code style are a little messy. Now let's talk about some immature experiences. Here we will mainly talk about the implementation of key functions, and download other components and their specific code. : Http://free.ys168.com /? Yyhlm, http://download.csdn.net/source/179332#aa
1. Overall Architecture
Based on the C/S mode (TCP/IP protocol ). The server is responsible for all game scheduling, monitoring the situation of each game player and data transmission. The client only receives commands from the server and responds.
2. File Layout
Main Program, DLL file (pure resource file, including playing card image data), sound file (point card sound ).
3. Poker Design
Define a single playing card class, store the points, colors, and IDs of playing cards (to facilitate identification and transfer IDs when uploading and inputting cards over the network, instead of passing the entire playing card class ), complete the display and size comparison of playing cards.
Define a playing card class, store all 55 cards (including one background), load the playing card resources, and complete shuffling. The shuffling algorithm is to randomly select two cards, swap their positions, and repeat them for 10 thousand times.
Define the card categories of players to compare their sizes.
Define the card categories that players take, complete the card-issuing action, and complete the automatic card selection function (this is a bit of a hassle. For details, see the code, and the author is lazy, so it is not perfect ).
4. Interface Design
Based on the MFC dialog box, the reason for laziness is simple. The key function of clicking a card with a mouse is to determine the position through the addition and subtraction operations of playing cards.
5. Network Communication
The key part is the data structure transmitted over the network. The data header and data format are used. For example, data header 0 indicates text data, and 1 indicates playing card data is transmitted, 2 is to start the game and so on (note that this is an example, and my code is not necessarily like this ). Both the server and client respond to these data headers.
Introduction to the gameplay.
The name of the game is "50 K". It is a point playing card game with three players playing with two sub-cards. In the end, whoever gets the most points wins (only 5 10 k points ). Card size comparison (similar to landlords): Same as 8 card points> same as 7 card points>...> five cards are the same> 50 K (only 50 K, three cards, and the same color)> four cards are the same> 50 K (meaning only 50 K three cards with different colors)> the three cards are the same, the two cards are the same, and the single cards (the three categories are equal to each other). The same number of cards are compared by the number of points, and the pure 50 K cards are compared by the black and red plums, 50 k is the same size. The cards that hold others in your hand cannot be ignored. If no one else can control your card, you can score the card.
: Http://free.ys168.com /? Yyhlm, http://download.csdn.net/source/179332#aa