Design and Implementation of the QT class for online wuziqi game in Huaqing vision learning Manual (5)

Source: Internet
Author: User

Design and Implementation of Network wuziqi game QT class (5)

 

Although the UI of the fourth version of wuziqi game is much more beautiful, it can only be played by itself or by two people. This article has always been advertised as "network", but still does not see its shadow.

Please wait. Let me draw a Tao Fu:

1. The original program is divided into two parts. The qtcpsever and qtcpsocket classes are added to implement network functions. TCP is used to synchronously update the server-side checker data and the client's checker data.

2. The server is a black player. First, open a port and listen to it, which indicates that the white player client sends a connection request. After the connection is established, the black player goes down first.

3. After either party clicks the mouse, the board data and current status should be reported to the other party in a timely manner.

4. If the network of either party is interrupted, the other party shall be able to give a prompt to choose to reconnect or quit.

5. The following is the header file of the main modified class implementation:

------- Heiqi (server side )-------

ChEssBase. h:

 

Class ChEssBase: Public qdialog
{
Q_object
Public:
ChEssBase (INT, char **);
Public slots:
Void slotturn (bool );
Void slotvictory (bool );
Void slotrestart ();
Void slotstart ();
Void slottransfordata (INT, Int, INT); // data sending slot


Void slotupdateserverdata (); // Update Server Data

Void slotacceptconnection (); // receives the connection

Void slotreporttcperror (q1_actsocket: socketerror); // report a TCP Error


Signals:
Void signalstart ();
Void signalrestart ();
Void signalclear ();
Void signalsetchess (INT, Int, INT); // chess Signal


PRIVATE:
Chessboard * Board;
Mychess * white;
Mychess * black;
Chessview * view;
Qlabel * statuslabel;
Qpushbutton * startbutton;
Qpushbutton * restartbutton;
Qpushbutton * quitbutton;
Qtcpserver tcpserver; // The server tcpsocket is used for listening.

Qtcpsocket * tcpserverconnection; // used to establish a connection with the client


Qint16 CX; // X coordinate of chess

Qint16 Cy;

// Y coordinate of chess



Qint16 status; // the current status.

Qint32 msgsize; // Message Size


, Not used currently

Qstring MSG; // message, not used currently

Qbytearray inblock; // receives data processing

Qbytearray outblock; // send data processing



};

------- BaiQi (Client Side )-------

ChEssBase. h:

Class ChEssBase: Public qdialog
{
Q_object
Public:
ChEssBase (INT, char **);
Public slots:
Void slotturn (bool );
Void slotvictory (bool );
Void slotrestart ();
Void slotstart ();
Void slotconnected (); // TCP connected slot

Void slottransfordata (INT, Int, INT );

// Data transmission slot



Void slotupdateclientdata ();

// Update client data



Void slotreporttcperror (q1_actsocket: socketerror );

// Report TCP errors



Signals:
Void signalstart ();
Void signalrestart ();
Void signalclear ();
Void signalsetchess (INT, Int, INT );

// Chess Signal



PRIVATE:
Chessboard * Board;
Mychess * white;
Mychess * black;
Chessview * view;
Qlabel * statuslabel;
Qpushbutton * startbutton;
Qpushbutton * restartbutton;
Qpushbutton * quitbutton;
Qtcpsocket tcpclient; // client tcpsocket




Qint16 CX; // X coordinate of chess

Qint16 Cy;

// Y coordinate of chess



Qint16 status; // the current status.

Qint32 msgsize; // Message Size


, Not used currently

Qstring MSG; // message, not used currently

Qbytearray inblock; // receives data processing

Qbytearray outblock; // send data processing



};

6. I started to give my WAF a half-covering face! The fifth version of the online version
Wuzi game:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.