0
How To move something in console using keyboad keys in C++
15 Respostas
+ 2
And because of what Martin Taylor said.
You're gonna need to rely on the operating system's API because it does have access to your keyboard and video memory.
On windows, some functions that come to mind would be:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate
To check if a key is down.
And
https://docs.microsoft.com/en-us/windows/console/setconsolecursorposition
To set the cursor's position so you can write to the correct spot.
Just make sure to read the documentation and don't expect it to be portable to other operating systems.
If you check all the console API functions, you might find out how to clear the screen as well without using something as silly as a system command.
0
I need to develop centipede game. So that snake have to move.How can I do it?
0
For the centipede you could use an array of points ( coordinate ).
Every move delete the last point and add a new point to the front based on the direction you're traveling in.
That way it looks like everything is moving.
Then simply iterate through it and draw something at each point.
0
how to delete the last point? I meant is there a specific function or something
0
Prasad The easy way would be to use an std::deque, where you can simply call .pop_back() to remove the last element and .push_front() to add something to the front.
https://en.cppreference.com/w/cpp/container/deque
0
Can you send that piece of code?😓
0
Well, sure, why not.
As an example:
https://code.sololearn.com/c515XsicXPAW/?ref=app
The centipede will move down and then all the way to the right until it overflows ( probably want to prevent that )
Read the documentation for more.
0
thanku broh❤️
0
Да я всё равно не чего не поиму
0
COORD{5,2},
};a error in this line
0
Prasad
No errors for me, m8.
What would be wrong about it?
0
Dennis see inbox bro
0
Zert:dgh
0
I maked that❤️