C++ Program: Number Puzzle Game on Turbo-C++

CWC
3 Min Read

In this programs a set of numbers are spread randomly and the user has to put numbers in correct format.

At line 9 we have a drawRectangle function which is used to draw a rectangle of given dimension on screen when graphics mode is there. In the main function first we have cleared the screen then defined some local variables and an interData array which will be used to store the data in program and in this array we have randomly filled numbers which are less than 16 and greater than equal to 0. Then we have initialized the graphics mode using initgraph function in the graphics.h header file.

Then we print the numbers on the screen as we have filled them in interData array. And then use the drawRectangle function to draw some fitting rectangles on the screen. Then we have printed the message on screen and set the background color to red of our graphics screen and prompt user how to use this game for playing. After this we have exited the graphics mode. Now we ll do everything in normal output mode.

After this we start the game prompting user to use arrow keys for moving different numbers across the screen and keep checking at each step if required pattern has been made by user, if user comes to the required pattern then we simply declare him win else we keep playing game keeping boundary conditions in our code logic.

Rest of the logic in code is for to get the value corresponding to each key press by the user. We identify from the ascii value of key which key has been pressed by the user and then accordingly we adjust values in our data structure. In this way we keep on doing this unless wither user wants to exit or he has reached to the particular pattern.

Here are some screenshots of running program-

Download C++ Program: Puzzle Game on Turbo-C++

[sociallocker]
Download C++ Program: Puzzle Game on Turbo-C++
[/sociallocker]

Save

Share This Article
3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version