Using QT to develop Chinese chess (i): overview

Source: Internet
Author: User
Tags emit linux mint

Recently read some about the realization of Chinese chess books, which tells how to develop a complete Chinese chess game, read the contents of the inside, feeling inside the content is particularly ingenious, such as the book mentioned the use of a chessboard to represent the Chinese chess board and some exquisite moves algorithm.     Based on these, I have also tried to develop a Chinese chess. I developed under the Linux Mint 17.1 32-bit operating system with the QT Creator 3.3.1,QT version of 5.4.1. Because of the more functions to achieve, plus a day can be smoked out of the time of up to two or three hours, usually busy working, development is intermittent. The whole process took me about three or four months. The feeling is still more painful, of course, there are some small sense of accomplishment. Source code Download Link: http://download.csdn.net/detail/zxywd/9172917. If you can make this thing out when you're in college, don't mention it. Okay, cut the crap, here's what you've achieved:
The whole game has three kinds of modes: oneself and oneself chess, Man-machine battle, network battle. From the function, mainly have these functions: Advances time limit, moves, undo, checkmate judgment, repeat situation detection (long will be sentenced to negative), save chess to file, from the file load chess, show.
For QT, the most notable feature is its signal-slot mechanism, which is an observer pattern. We often use them in the code. The whole design is as follows:
1.MainWindow class: The main interface of the game, including menus, toolbars.
2.ChessBoard class: Display board and chess pieces.
3.StepList class: Displays a list of Chinese text.
4.ChessHandler class: The logic layer of the game.
5.MoveGenerator class: To judge whether the moves is reasonable and to generate the law.
6.servernetwork/clientnetwork class: Network in wartime, used to send moves messages and other messages.
7.GameSettings class: Save and load the game settings.
The MainWindow encapsulates a chessboard object, two Steplist objects, and a Chesshandler object. The MainWindow category is equivalent to the observer, and the chessboard and Chesshandler are equivalent to the observed. Because the chessboard and Chesshandler classes have the specified signal connected to the slot in the MainWindow. For example, when moves, chessboard respond to mouse events, and then emit the specified Signal,mainwindow call slot, slot Chesshandler in the moves logic, chesshandler after the moves is over, It also emit the specified Signal,mainwindow call slot update steplist and chessboard, and finally completes a complete moves logic. In the signal-trough this aspect, only from chessboard to MainWindow and Chesshandler to MainWindow, there is no reverse, otherwise it will appear chaotic, and also not worth, after all, is a member of the MainWindow, direct call is. Chesshandler and chessboard do not have a pointer to save MainWindow, can not directly call the method in MainWindow, only through the signal-slot mechanism to achieve.

Here's a screenshot of the game:


Some of the icons inside are casually looking, the interface is more ugly, I hope you do not mind.

When I was in college, my seniors used Java to develop a game of Chinese chess, at that time, they all felt so much cow, now want to think, they thought too immature. It can be said that if it takes 200 hours, or not so long, you can make this thing come. If you don't believe it, you can try it. There will be more introductions in the following articles.

Source code Download Link: http://download.csdn.net/detail/zxywd/9172917


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.