Domanda

I was making this game on c++ in which coins keep on increasing and user can decide what to do with them, however the game stops for the user to enter the command. What i want is that coins keep on stacking up and if the user wishes to do something with them then he enters a number to perform the specific task.

È stato utile?

Soluzione

Due the lack of information I'm just going to jump to the simplest answer.

USE THREADING

You could do something like this:

PSEUDOCODE WARNING:

MainThread:
  Wait for user instructions
  Lock Coins Variable
  Expend their coins
  Unlock Coins Variable

CoinThread:
  Increase Coins all the time

Simple as that

Altri suggerimenti

From my understanding of the question and your comments, it seems you are trying to re-invent the wheel. You should take a look at Qt. It has its own eventloop which will handle the GUI for you.

If you do not want to use Qt then please multi thread your application so that the main thread is waiting for the cin while the other thread is running your coins.

PS: It would have been much more easier if you had posted your code.

kbhit is the exact function, it sees if a parameter is available without stopping the program specifically for the command it is defined within the header file conio.h

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top