Use MFC to complete a simple guess number game: the input four digits, the position and number are correct a, the same number and the location of the difference is B.

Source: Internet
Author: User

Recently learned some of the basic knowledge of MFC, so I intend to do a simple digital game to understand the process of MFC and further familiar with its operations.

Here, I made a guess number of small game. The first step of course is to design the main interface, first show you the game interface :

Main interface:

From this main interface you can see that it contains the title, menu bar, and toolbar .

The title is to give people an understanding of what the game is, the title is set to: "Guessing game";

and the menu bar and toolbar is the core of the game, it must be able to complete the basic functions of the game.

The menu bar and toolbar are corresponding, including the "Start", "Help", "Restart" The three menu responses . It is clear that both "start" and "Restart" are realized by "starting the game" and "restarting the game"; Help is a description of the rules of the game.

click "Help" or the icon with a blue question mark, you can read the information about the game, here I use the Display dialog box to express:

The dialog box displays the rules for guessing the number game , which is to enter four non-repeating numbers, and then click OK button to display the results in the output.

In the four digits of the input, the positions and numbers are correctly A, the numbers are the same and the positions differ by B. If you still don't guess nine times, the game is over.

Click OK to go back to the main screen.

So, now the main thing is "start" to achieve the function of the game, we can first design the game on the paper on the initial interface of the approximate mode. This mode mainly refers to: game input parameters, game output parameters and so on.

In this process, I was based on the need to implement the function, first in C language and test. Then according to the parameters of the program, you design a clearer, user-friendly operation of the game start interface .

According to some static text hints in the dialog box, we can know that we only need to enter four distinct numbers in the text box after "Enter four digits:", and when you click the "OK" button, the other text boxes will be displayed according to the results of the programmed program .

Remember that when doing the test, be sure to consider all possible situations: If the user himself entered a four-digit number is repeated, we have to prompt him to re-enter, that is, the following screen is displayed:

Now to analyze the game output parameters are:"Output Results"----description format *a*b, as described in the game rules;

"Number of attempts"---the number of guesses , because the game is limited to 9 times, which reminds users of the role, but also to a certain extent reflects the user's ability;

" game time" can be used as another indicator of game level ";

"correct answer"---some users play half don't want to continue, or the game fails, want to see the correct answer, then just click the button;

The history---is the number of guesses that are recorded and their corresponding output results.

Of course, this correct answer is generated randomly by the program, each time there is a difference, and the four-digit number is not duplicated.

Next, we will try to play this game, by the way test game success or failure after the indicators can be consulted:

As you can see, the four digits of each input are recorded in the history and their results, the current number of attempts is 9, time 47s, but has not guessed, then the display "Unfortunately the game failed!" dialog box.

And now this operation, showing "4a0b" is the success, the number of attempts to 3, time 15s, and prompted "Congratulations on your success!" ”。

If you want to continue playing, click "Restart" and you can play again.

All in all, this game is relatively simple, involving MFC's menu bar, toolbars, dialog boxes, text output and some control processing, of course, there are some places do not be perfect or there are other features not,

But the key is to master a more complete MFC process, and in the implementation process of the integration of the various modules and some details processing!

Use MFC to complete a simple guess number game: the input four digits, the position and number are correct a, the same number and the location of the difference is B.

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.