Foreword
I made a project in the second half of last year and is a online game of a poker. Original plans include: arch pigs, landlords, bus, red five three, one, etc. But the most important project abortion, only completed the arch pigs and red five three. When starting at last year, online related information is rare (generally a very simple game), especially in Win32, the MFC is more than the MFC. I mainly refer to an foreigner article. This article mainly expounds how to draw a pair of playing cards, and demonstration procedures, and the demonstration procedures. It is impossible to find the source code for the group or the midstream. Therefore, its design is still realized. At present, the project is abortion, and I don't want to let it sleep in the hard drive. I am willing to put some of the stoveted to share with everyone, and I have a kind of self-自.
Overview
Divide
Network layer and
Application,
The network layer is completed and encapsulated by classmates, and the application layer is completed by the author. In the author
When the application layer, only need to know the network layer has the following characteristics:
1. Each player runs a program instance on its respective computers. Each instance is defined as a "here"
end".
2, there is one in the ends "
Host "," Host "is directly responsible for contacting the game server, namely, from the carrier's server to download the points and other information; and responsible for distributing the message to other players. In the end, the" host " Corresponding, defined "
Start.
3, the service provided by the network layer: distributes messages from this end application layer to all other ends; send messages sent by other ends to the local application layer. And guarantee
Correctness,
Time series.
The principle of designing application layer should be as follows by the characteristics of the network layer above:
1. Define people who participate in the game "
Player. "Each player has an abstract mapping on each end, namely one
Player. If a game has N people (N players), on each end, there are N PLAYERs. One of the N players in the node is
local(
Local
), Other N-1 is
Remote
(REMOTE). The local (local) is accepted from the GUI message and issues a message to the Player (Remote) of the same player. Remote Player does not accept messages from the GUI to accept messages from remote Player (local). Therefore, with the Remote-local structure, the application layer synchronizes all the Player corresponding to each of the players, maintains the consistency of each parameter.
2, peel off the game and interface,
GAME and
VIEW two classes. The GAME class is responsible for setting different rules based on different games, with different games. There are several basic functions that need to be realized by virtual functions:
l Size comparative rules
However, the size of the card or group card is compared.
l Examination legal judgment rules
If the card is not a combination allowed by this rule, it is returned.
l Delivery order
Every bureau, every round, everyone who first walks, who will take the card.