can I display realtime feedback in a terminal game?

300 views Asked by At

I'm trying to write a simple terminal-based dungeon-style game in C, but I want to give the user real-time feedback on various processes that they affect.

I remember using kbhit() years ago, but I also remember the cpu going to 100% during the life of the program. I'd like to avoid this entirely. And I'm working in Linux now.

Let's say that you're in a dungeon in a text-based adventure game. The dungeon is sealed off. There's only so much air in the room. The longer you remain there, the lower the oxygen gets. I want to report the oxygen level in the room in real-time, while at the same time accepting commands from the user.

Is there a way to do this?

EDIT: The one idea I had was to use two terminal windows. Commands are taken in one terminal, the results of those commands could be written to a text file. The other terminal will have a program running that runs real-time stuff, and checks periodically on the same text file for updates on rates, etc. Ideally, I'd like to do this in one window.

1

There are 1 answers

0
Andreas On BEST ANSWER

Sure there is a way to do that. Have a look at ncurses. I think that is the way to go.