Mình có viết thử game rớt chữ . Đến lúc test thử thì VS15 cứ báo lỗi không dùng được hàm kbhit và getch. Copy qua devC++ thì chạy vô tư. Ai biết tại sao bày mình với .
#include<iostream>
#include<math.h>
#include<windows.h>
#include<ctime>
#include<conio.h>
using namespace std;
void gotoxy(short x, short y)
{
HANDLE hConsoleOutput;
COORD Cursor_an_Pos = { x,y };
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}
void layout() {
/*gotoxy(0, 0);
for (int i = 0; i < 5; i++) {
cout << " "<<endl;
}*/
gotoxy(0, 0);
cout << " ";
for (char i = 'A'; i <= 'Z'; i++) {
cout <<" " <<i;
}
gotoxy(0, 20); cout << "_______________________________________________________";
}
int chuRoi() {
srand(time(NULL));
int col = rand() % 26 + 1;
int i = 0;
while (i<20 && !kbhit()) {
gotoxy(col * 2, i);
cout << " ";
gotoxy(col * 2, ++i);
cout << char(64 + col);
Sleep(400);
}
gotoxy(0, i);
cout << " ";
gotoxy(0, 0);
cout << char(64 + col);
if (i < 20) {
char c = getch();
if (c == char(64 + col) || c == char(94 + col))
return 1;
else return 0;
}
else {
gotoxy(0, 20);
cout << "_";
return 0;
}
}
int main() {
layout();
chuRoi();
system("pause");
}