Reaction Test Game (Variant)

A variant of the reaction test game with slightly different beep sound implementation. Uses BGI graphics to display directional arrows and measures user reaction time.

Source Code:

Program ReactionTest;

uses Crt, Dos, Graph;

type TASet = (Up,Down,Left,Right);
     TPArray = array[1..4] of PointType;
     TArrow = array[TASet] of TPArray;

const
     Arrow : TArrow =(
     ((X: 50; Y: 270), (X: 300; Y:100),(X: 550; Y: 270), (X:  50; Y: 270)),
     ((X: 50; Y: 170), (X: 300; Y:350),(X: 550; Y: 170), (X:  50; Y: 170)),
     ((X: 200; Y: 220), (X: 350; Y:50),(X: 350; Y: 400), (X:  200; Y: 220)),
     ((X: 400; Y: 220), (X: 250; Y:50),(X: 250; Y: 400), (X:  400; Y: 220))
     );
     Esc: char = #27;
     Gray : FillPatternType = ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff);

var
  CoSym,MySym : char;
  ADel,Del,Time : real;
  i: integer;
  Errs: Integer;
  Hits: Integer;
  grDriver: Integer;
  grMode: Integer;
  ErrCode: Integer;

procedure DrawArrow(A:TASet);

begin
    ClrScr;
    FillPoly(SizeOf(Arrow[A]) div SizeOf(PointType), Arrow[A]);
end;


Procedure Wait;
begin
     repeat until KeyPressed;
end;

Procedure Beep(Dur:integer);
begin
    Sound(500);
    Delay(Dur*100);
    NoSound;
end;


Function TrueHit:boolean;
begin
     if MySym=CoSym then
          begin
               Inc(Hits); TrueHit:=true;
          end
     else
         begin
               Beep(1); Inc(Errs); TrueHit:=false
         end
end;

function ShwSym:Char;
begin
  Randomize;
   case Random(4) of
	0 : begin DrawArrow(Up);ShwSym:='8';end;
	1 : begin DrawArrow(Down);ShwSym:='5';end;
	2 : begin DrawArrow(Left);ShwSym:='4';end;
	3 : begin DrawArrow(Right);ShwSym:='6';end;
   end;
end;

function Dellay : real;
var  h, m, s, hu : Word;
     Del,MarK : real;

begin
     begin
     GetTime(h,m,s,hu);

     Wait;

     MarK:=s+hu/100 ;
     GetTime(h,m,s,hu);
     Del:=(s+hu/100)-Mark;
	  iF Del < 0 then Del:=60-Mark+(S+hu/100);
     Dellay:=Del;
     end
end;


begin
  ClrScr;
  grDriver := Detect;
  InitGraph(grDriver, grMode,'');
  ErrCode := GraphResult;
  if ErrCode = grOk then
  begin  { Do graphics }
    TextColor(0);
    SetColor(0);
    SetBkColor(0);
    SetFillPattern(Gray, Random(16));

      repeat
            CoSym:=ShwSym;
            Del:=0;

            repeat
	          Del:=Del + Dellay;
	          MySym:=ReadKey;
            until (MySym=Esc) or TrueHit;

            ADel:=(ADel+Del)/2;
            Time:=Time+Del;
      until MySym=Esc;

    CloseGraph;
    TextColor(12);
    GotoXY(15,10);
    WriteLn('‘।­ïï § ¤¥à¦ª  ',ADel:0:4, ' ᥪ㭤 §  ¢à¥¬ï ',Time:0:0,' áãªã­¤');
    GotoXY(30,13);
    WriteLn('Žè¨¡ª¨: ',Errs,' �®¯ ¤ ­¨ï: ',Hits);
    Wait;

  end
  else
    Writeln('ƒà ä¨ç¥áª ï ®è¨¡ª :', GraphErrorMsg(ErrCode));
end.