I'm trying to code a kind of simple video game where there are two kind of players:Human Players: They enter an keyboard inputCPU Players: A random input is calculatedFor Human Players there is a T round time and a T' input entering time. Let's say, if T=20 and T'=5, a player has 20 seconds to start typing, but only 5 seconds of typing time. So, if the player starts typing at T=10, will only be able to type those T'=5 seconds until T=15.Just so you know, I'm using Typescript, and I had something like this in mind:while (!gameOver) {   // do some stuff like knowing who's player turn is it   var enteredInput;   if (player.isHuman()) {      enteredInput = captureKeyboardInputsFor(seconds);   } else {      enteredInput = calculateRandomCPUPlayerInput();   }   // process input & do actions}What I would like to achieve here is a kind of synchronous typing process, I have the game logic well defined in mind, but I'm trying to figure out how can I do this keeping my loop game synchronous (as the players play in turns), using TypeScript.I would really appreciate any kind of guidance, alternatives or ideas of possible ways of solving my concerns.
Capturing keyboard events for a limited time
javascript;programming practices;event programming;asynchronous programming;typescript