Reaction Test Game

A graphical reaction time test game. Displays arrows in different directions and measures user reaction time. Uses BGI graphics, tracks hits/errors, and calculates average 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,k: 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(Mood:boolean);

begin
case mood of
True: begin
 Sound(100); Delay(1000); Sound(300); Delay(750); Sound(500);  Delay(500);
  NoSound;
    end;
False: begin
  Sound(500);  Delay(500);  Sound(300);  Delay(750);  Sound(100);  Delay(1000);
  NoSound;
    end;
end;
end;

Function TrueHit:boolean;
begin
     if MySym=CoSym then
          begin
               Beep(True);  Inc(Hits); TrueHit:=True;
          end
     else
         begin
               Beep(False); 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

    TextColor(0);
    SetColor(0);
    SetBkColor(0);
    SetFillPattern(Gray, 11);

      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(10);
    GotoXY(15,10);
    WriteLn('‘।­ïï § ¤¥à¦ª  ',ADel:0:4, ' ᥪ㭤 §  ¢à¥¬ï ',Time:0:0,' áãªã­¤');
    GotoXY(30,13);
    WriteLn('Žè¨¡ª¨: ',Errs,' �®¯ ¤ ­¨ï: ',Hits);
    Wait;

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