我试图用控制台获得快速时间事件类型的交互,并设法使用conio库获取它。可悲的是,我正在开发的这个项目需要在Windows和Linux上编译代码,我无法找到一种方法来改变它。有没有办法在标准C中替换kbhit()和getch()函数?
有什么我可以做得到理想的效果还是应该放弃这个概念?以下是我创建的函数的代码。
#include
#include
#include
#include
#include
void battle(int x) {
srand(time(0));
printf("Use Q to dodge projectile attacks, E to block melee attacks and W to attack when the boss is stunned. Button mashing will not work! Press any key to start the battle.\n\nYou face Brutus, Lord Incarcerator!\n\n");
getchar();
bool ok;
int dealt = 0 ,recieved = 0 , state, prev = 0;
time_t start, end;
double elapsed;
while(dealt < 5 && recieved < 3)
{
do
{
state = rand() % 3 + 1;
}
while(prev == state);
pre