console - How can I detect elapsed time in Pascal? -


i'm trying create simple game in pascal. uses console. goal in game collect many 'apples' can in 60 seconds. game structure simple infinite loop. each iteration, can make 1 move. , here's problem — before make move (readkey), time can pass as wants. example, user can press key after 10 seconds! there way count time? need program know when user plays (before , after key pressed), don't know how prevent user "cheating".

here's simple structure of game:

begin     repeat         {* ... *}         case readkey of             {* ... *}         end;         {* ... *}     until false; end. 

full code: http://non.dagrevis.lv/junk/pascal/parad0x/parad0x.pas.

as far know there 2 possible solutions:

  1. gettime (from dos),
  2. delay (from crt).

...but don't know how use them loop.

check this link. there might useful information you. , here is same you're asking for. , here's you're looking (same code below).

var hours: word;     minutes: word;     seconds: word;     milliseconds: word;  procedure startclock; begin   gettime(hours, minutes, seconds, milliseconds); end;  procedure stopclock; var seconds_count : longint;     c_hours: word;     c_minutes: word;     c_seconds: word;     c_milliseconds: word;  begin   gettime(c_hours, c_minutes, c_seconds, c_milliseconds);   seconds_count := c_seconds - seconds + (c_minutes - minutes) * 60 + (c_hours - hours) * 3600;   writeln(inttostr(seconds_count) + ' seconds'); end;  begin   startclock;    // code want measure    stopclock; end. 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -