I would like to know how to implement generation, movement and shooting of opponents in the console.

Here is a video that shows this implementation: https://www.youtube.com/watch?v=90EiQsBGoBY&t=71s

Closed due to the fact that the essence of the question is incomprehensible by the participants Alexey Shimansky , Nicolas Chabanovsky ♦ 24 Dec '16 at 7:34 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • in the console, most likely no way. But in general, the guides / examples on the development of igor are complete. main hint - enter the necessary in Google search - Volodymyr
  • @Volodymyr is not yours. In the console, this is done a little more difficult than usual, because: 1 - there are no ready-made engines, 2 - the console slowly redraws. Nevertheless, this is not possible. - rdorn

1 answer 1

Look, there are two flaws in the console, which, in other matters, did not stop anyone when the text display was considered a luxury, and the graphic display was fiction. Yes later too. They even redrawn the fonts, so that not small letters, but little men, or even some evil spirits, run across the screen. Square sprites of platformers, originally from there, the only thing that distinguishes them is the smoothness of the offsets, the symbol can only be moved entirely to the next position, and the picture can be moved half the cell imitating smooth movement, although behind the scenes all the same cells. Now of course everything is much more complicated and easier at the same time.

The first drawback is probably a joke, but nevertheless - the lack of ready-made libraries for console graphics in modern software, although the same Turbo Pascal had libraries even for drawing window interfaces in the console. At the same time, the capabilities of the console available in .NET are rather poor, but since you asked such a question, I hope you are not afraid of difficulties.

The second drawback is already serious - the console output speed. If you plan as usual to completely redraw the entire screen every 50-100 ms, then you will get a wild screen flicker, and no buffering will save you, since it simply does not exist. Although on older machines it was possible to write directly to the text buffer of the screen, now there is no such possibility, at least on .NET

What you will need:

Find characters that are not on the keyboard, but which are convenient to draw what you want to see in the console, and learn how to insert them into the code in one way or another.

Learn how to update only the necessary parts of the text box, i.e. if you need to replace one character - you need to output exactly one new character, exactly in the right place, if you need to move a character - we output two characters, one in the new place and one in the old one. Such manipulations are performed using the methods Console.SetCursorPosition (Int32, Int32) and Console.Write (Char)

Learn not to move the console image up. To do this, you need to find out the actual size of the text box (80x25 by default) and not allow the output \n under any circumstances, only hardcore, only manual positioning, of course this applies only to the bottom line, but it is very easy to forget where the text cursor is, especially if it is disabled, we do not need to blink the cursor on the screen, the game is all the same.

Learning to get input from the user without an echo response, i.e. so that after pressing a key, the corresponding character is not displayed in the console. To do this, you need the Console.ReadKey (true) method.

Learn to work with color, if of course you need. At the console, you cannot set the output color of a single character, but already output characters retain their color until they are overlapped with the next output. Thus, to display characters in different colors, you need to switch colors of the console in a timely manner and do not forget to return them to their original state, otherwise all subsequent output will be the color to which you switched last time.

Well and the most difficult, is the organization of the main cycles of your program. Here you need to take into account everything, and all this will have to be taken into account with your hands. When to draw changes on the screen, when to watch what the user has clicked or entered, when to calculate the actions of enemies and user, etc. etc. The console does not provide input events, so you have to keep track of all this yourself.

Practical advice: start to master the console graphics with something simpler, for example with the "snake". The algorithm of the game is simple, but you can work out the subtleties of working with console output before you end up with real problems, eventually add to the opponent's snake and learn to shoot =).

  • “Although it was possible to write directly on the text buffer of the screen on old machines, now there is no such possibility, at least in .NET” - well, if the console application runs in a window, the concept of “text screen buffer” is not present, there are many windows on the screen. But the text buffer of this console is there, and you can work with it via P / Invoke: docs.microsoft.com/en-us/windows/console/ ... Although, oddly enough, it is called the console screen buffer. - VladD
  • @VladD well, this is WinAPI already, and not .NET itself =) Although thanks for the tip, somehow I'll try to squeeze it out =) - rdorn