Timer URGENT

I have created a maze and i wish to add a timer to record the time taken to finish it.

any help how to do it?

Comments

  • : I have created a maze and i wish to add a timer to record the time
    : taken to finish it.
    :
    : any help how to do it?

    Go back on this forum about a year or two, it was discussed back then, if my memory serves me right.
  • This post has been deleted.
  • program guess_the_number;
    uses windows;
    var a,b,tries:byte;
    time:dword;

    begin
    randomize;
    tries:=0;
    a:=succ(random(100));
    time:=gettickcount; { <-- Get time from system counter, it gets updated every millisecond }
    repeat
    write(#13#10'Enter a number between 1 and 100 (0 to Exit) : ');readln(b);
    inc(tries);
    if b=0 then begin writeln(#13#10'Exiting...');halt;end;
    if a<b then writeln('Too big...') else
    if a>b then writeln('Too small...');
    until a=b;
    time:=trunc((gettickcount-time)/1000); { <-- calculate elapsed time }
    writeln(#13#10#13#10'You took ',time,' seconds and ',tries,' tries to guess it.');readln;
    end.

    i) do i need to install anything? it shows Syntax error, BEGIN expected but identifier WINDOWS found
    ii) how can i show the time without delaying the character's movement?
  • : i) do i need to install anything? it shows Syntax error, BEGIN
    : expected but identifier WINDOWS found

    The version you posted is written for Free Pascal...

    : ii) how can i show the time without delaying the character's
    : movement?
    :

    It can be done quite a few ways, and it all depends how your game is set up... I suppose your game has a main loop where everything takes place, so include it in there. Here's a pseudo code to show you what i mean:[code]{...}
    < get initial time here >

    repeat { <--- that's the main loop}
    < get user input >
    < follow up with user input >
    < ... >
    < calculate score, movements, follow game logic etc... >
    [red]< calculate time passed >[/red]
    < do display > <--- because this happens multiple times per second will be no character delay
    < possible delay here is game runs too fast >
    until ( { conditions needed to break the loop here } ); { <-- main loop ends}

    {...}[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories