c语言kbhit函数头文件,有没有办法在标准C中替换kbhit()和getch()函数?

这篇博客探讨了如何在Windows和Linux上编写跨平台的控制台交互代码,作者询问是否有可能在标准C中替代kbhit()和getch()函数。文章展示了一个战斗模拟游戏的示例,该示例在不同平台上可能遇到问题。评论建议使用其他方法,如在Linux环境下寻找等效实现。
摘要由CSDN通过智能技术生成

我试图用控制台获得快速时间事件类型的交互,并设法使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值