實(shí)際上就是這樣。在這張照片中,當(dāng)我點(diǎn)擊這里。汽車停下來了。
您可以在github的這個(gè)鏈接中找到原始代碼。
#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 << " ";
}
}
它基本上是在汽車行駛的過程中打印汽車,然后在前面打印的位置上加上空格。
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;
}
在控制臺(tái)選項(xiàng)(左上角按鈕)中,轉(zhuǎn)到屬性并關(guān)閉“快速編輯模式”設(shè)置。這是一個(gè)Windows功能,單擊鼠標(biāo)可暫停正在運(yùn)行的任何程序,并允許您從屏幕上選擇文本。你不想在你的節(jié)目中這樣做。