Home > Net >  i'm making a console game (on cmd), when i touch the screen with my mouse. how do i make it ign
i'm making a console game (on cmd), when i touch the screen with my mouse. how do i make it ign

Time:05-19

literally just that. in this pic when i clicked here. the car stopped coming down.

you can find the original code in this link from github.

#include<iostream>
#include <windows.h>
#include <time.h>
using namespace std; //don't hate me for it i started coding a day ago.

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coords;
int carY[3];
int carX[3];
int carFlag[3];
void gotoxy(int x, int y) { //change the cordinates the text outputs to
    coords.X = x;
    coords.Y = y;
    SetConsoleCursorPosition(console, coords);
}
void gencar(int ind) {//ind means indeterminate.
    carX[ind] = 40;
}               
void drawcar(int ind) {
    if (carFlag[ind] != false) { 
        gotoxy(carX[ind], carY[ind]); cout << "****";
        gotoxy(carX[ind], carY[ind]   1); cout << " ** ";
        gotoxy(carX[ind], carY[ind]   2); cout << "****";
        gotoxy(carX[ind], carY[ind]   3); cout << " ** ";
    }
}
void erasecar(int ind) { //fills old places with spaces
    if (carFlag[ind] != false) {
        gotoxy(carX[ind], carY[ind]); cout << "    ";
        gotoxy(carX[ind], carY[ind]   1); cout << "    ";
        gotoxy(carX[ind], carY[ind]   2); cout << "    ";
        gotoxy(carX[ind], carY[ind]   3); cout << "    ";
    }
}

it basically prints a car as it's going down and over prints the previous print's position with spaces.

int main()
{
    carFlag[0] = 1;
    carY[0] = 1;
    gencar(0);
    while (1) {
        drawcar(0);
        Sleep(60);
        erasecar(0);
        if (carFlag[0] == 1) //makes it move on the Y axis
            carY[0]  = 1;
    }
    return 0;
}

CodePudding user response:

In your console options (the top left button), go to Properties and turn off the "QuickEdit Mode" setting. This is a Windows feature where clicking the mouse suspends whatever program is running and lets you select text from the screen. You don't want that for your program.

  •  Tags:  
  • c
  • Related