P
P
Pinkman2020-03-26 18:30:58
C++ / C#
Pinkman, 2020-03-26 18:30:58

How to implement movement in the terminal?

The task is this: I want to make a snake in C. I realized that you can move the cursor (in the terminal) through escape sequences. But the problem is that I don't understand how to move the cursor to a straight line. like I press the up arrow and the cursor goes up, to the right - goes to the right, etc. How can this be done?
And an additional question, how to find out the size of the terminal through an escape sequence?
PS ncurses.h do not offer =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2020-03-27
@famousman204

I don’t remember all the details of the implementation of the class for working with the console, but I can accurately indicate the directions for searching for the following:

  • Function to get console handle: GetStdHandle;
  • a buffer of chars was created the size of a playing field of a given size (100x80). Then the SetConsoleScreenBufferSize function set the console buffer to the size of our buffer;
  • To fill the console by its handle from the buffer, use the WriteConsoleOutput function

Updating the console buffer must be carried out by a timer, but I don’t remember how it was implemented there. That is, according to the timer, it is necessary to redraw the entire console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question