Good day! I am trying to implement the Tamagotchi game (C ++, a console application). Over time, an object of the Tamagotchi class should starve: its hunger level should increase by one for each unit of time (for example, by +1 for every 60 seconds). How to realize this opportunity?
The main interface of the program is implemented on a while loop: the user enters commands that are interpreted by the program as “feed”, “walk”, I don't know, “play”, and so on.
Actually, the question is from 2 parts:
- How to implement a change in the value of the variable (hunger) once a minute? Can this be done in a modern way? With ++ 11, there, all affairs. The only thing that comes to mind is to create a cycle that will work until the difference between the start of the cycle and the current moment t0-t1 is more than 60.
- Is it possible to realize this change of value against the background of the running while loop (the program communicates with the user) without threading? That is, so that I do not have to wait for the end of the 60-second cycle to enter a command into the console.
Thank you in advance.