Here I wrote:
#include <iostream> #include <conio.h> #include <cstdlib> #include <Windows.h> using namespace std; char a[100][100]; //Початкові координати int sx = 15, sy = 10; //Напрям int direct; void view(); void border(); //Напрямок int direction(int direct) { if (direct == 0) return sy--; if (direct == 1) return sx++; if (direct == 2) return sy++; if (direct == 3) return sx--; } int main(){ while (getch() != 27) { border(); Sleep(500); switch (getch()) { case 72: direct = 0; break; //вгору case 77: direct = 1; break; //вправо case 80: direct = 2; break; //вниз case 75: direct = 3; break; //вліво } direction(direct); for (int i = 0; i < 20; i++) for (int j = 0; j < 60; j++) { a[sy][sx] = '0'; if (sy >= 19 || sy <= 0 || sx >= 59 || sx <= 0) goto gameover; } system("cls"); view(); } gameover: cout << "Game over..." << endl; system("pause"); return 0; } //Границі поля void border() { for (int i = 0; i < 20; i++) for (int j = 0; j < 60; j++) { a[i][j] = ' '; a[0][j] = '#'; a[i][0] = '#'; a[19][j] = '#'; a[i][59] = '#'; } } //Малює поле void view() { for (int i = 0; i < 20; i++) { for (int j = 0; j < 60; j++) { cout << a[i][j]; } cout << endl; } } Question: I don’t understand the moment with time, therefore I don’t have the right idea here. Please help me make sure that when passing every second the element "0" is moved in the right direction.