Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
3.20/5 (3 votes)
See more:
I have made 2D array for displaying the board of pacman game.I want to move the actor by using keys pressed like 'w' or 's' or 'd' or 's' in 4 dimensions on console just like in this link .Is it possible to refresh 2D array in C++ console .How i can accomplish this task?
Posted
Updated 20-Dec-13 5:50am
v2
Comments
Sergey Alexandrovich Kryukov 20-Dec-13 11:32am    
Do you mean console, text console. Are you writing the pacman game on a console?! Well, this is possible, but why? Cross-platform, maybe?
Anyway, it is not related to "2D array" or something...
—SA
Member 8920414 20-Dec-13 11:41am    
the problem is we are recommended to use only array or pointer data structure not even classes or graphics library....until now board is complete just like in youtube link and on each keyboard input complete broad is redisplayed .What i want to refresh that the board on console
Sergey Alexandrovich Kryukov 20-Dec-13 12:25pm    
I answered your question, did you notice it?
—SA

Please see my comment to the question. If this is really a console, a text console in a standard console-only application type, there is no "refresh" or some usual even-oriented features. You should simply redraw the whole console "screen" again, the same way as you did it before modification of your data. However, it is always better to locate only the subset of the console points to be updated and redraw only the changed part.

The whole activity in a text console is pretty weird for these days and not really so simple. I would say, making a usual graphical game based on GDI+ or DirectX (or one of higher-level graphical UI frameworks, such as MDI, Qt, Gtk+) would be easier. However, developing such a game on a console-only application is quite possible.

—SA
 
Share this answer
 
v2
Comments
CPallini 20-Dec-13 12:31pm    
My 5.
Sergey Alexandrovich Kryukov 20-Dec-13 12:37pm    
Thank you, Carlo.
—SA
In order to accomplish your task you might use the Console Functions[^] on Windows, and ncurses on Linux (see, for instance "NCURSES-Programming-HOWTO"[^].
 
Share this answer
 
Comments
Member 8920414 20-Dec-13 12:03pm    
Our teacher has strictly instructed us not use any graphics library or 3rd party api .We are taught C++ until array so we are bound to use until array....
CPallini 20-Dec-13 12:26pm    
If you can use only C++ iostream then you have to do what already suggested by Sergey: rewrite the entire screen (that is the whole array) on each (even minimum) change.
[no name] 21-Dec-13 1:39am    
If you are using Windows the console functions as suggested should conform with your teachers requirement as they are neither a graphics library or 3rd party api. Perhaps you should check. There is plenty on the web about game programming using the console functions to do exactly what you are asking.

It also seems a reasonable question so the downvoting is puzzling.
Sergey Alexandrovich Kryukov 20-Dec-13 12:26pm    
5ed. However, what OP does can make some sense: the study.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900