SRL Archive - General

Reaction speed tester


rj

2013-06-24 22:52:29

I don't consider this a script but here is a neato little reaction speed tester made with simba:



Move your mouse to the squares, it will test the amount of time it takes between each time you hover over a rectangle! The background color and shape color/size change each time to mix it up!

The score is kind of pointless, I just added it for fun. The smaller the rectangle the more points you get!

Example results:
***************Results***************
Score: 92306
Sample size: 15
Average points per square: 6154
Average reaction time: 710 ms
*************************************


code:

{$I SRL/SRL.Simba}
Var
GameForm:TForm;
sq:Tshape;
IntialSpawn, squarepresent:Boolean;
score:extended;
t, g, hits, reply:integer;
samplesize:string;

Procedure EndGame;
begin
Cleardebug;
if (hits>=StrToInt(samplesize)) then
begin
writeln('***************Results***************');
writeln('Score: ' + ToStr(Round(score)));
writeln('Sample size: ' + samplesize);
Writeln('Average points per square: ' + ToStr(Round(score/(StrToInt(samplesize)))));
Writeln('Average reaction time: ' + ToStr(G/(StrToInt(samplesize))) + ' ms');
writeln('*************************************');
end else if (hits<StrToInt(samplesize)) then writeln('You did not test enough!');
end;

procedure NewEvent(Sender: TObject; Shift: TShiftState; x, y: Integer);
begin
if (hits>=StrToInt(samplesize)) then GameForm.CLOSE;
GameForm.color := random(16777215);
g := g + TimeFromMark(t);
Score := Score + (40000/sq.width) + (40000/sq.Height) + (500000/TimeFromMark(t));
hits := hits+1;
sq.Width := random(35) + 5;
sq.Height := random(35) + 5;
sq.left := random(500);
sq.top := Random(500);
sq.PEN.color := random(16777215);
sq.BRUSH.color := random(16777215);
sq.ONMOUSEMOVE := @NewEvent;
MarkTime(t);
end;

Procedure CreateSquare(Sender:Tobject);
begin
if not (IntialSpawn) then
begin
IntialSpawn := true;
sq := tShape.Create(GameForm);
sq.parent := GameForm;
sq.Visible := true;
sq.Width := random(40) + 10;
sq.Height := random(40) + 10;
sq.left := random(GameForm.Width-15);
sq.top := Random(GameForm.Height-15);
sq.PEN.color := random(16777215);
sq.BRUSH.color := random(16777215);
sq.ONMOUSEMOVE := @NewEvent;
MarkTime(t);
end;
end;

procedure InitForm;
begin
GameForm := TForm.Create(nil);
GameForm.caption := 'Reaction speed tester';
GameForm.color := random(16777215);
GameForm.Left := 250;
GameForm.top := 250;
GameForm.Width := 600;
GameForm.Height := 500;
GameForm.OnClick := @CreateSquare;
end;

procedure SafeInitForm;
var
v: TVariantArray;
begin
SetLength(V, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
try
GameForm.ShowModal;
except
writeln('ERROR WITH THE FORM');
end;
end;

procedure SafeShowFormModal;
var
v: TVariantArray;
begin
SetLength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;
begin
inputquery('Sample size','How many times would you like your reaction to be tested?', samplesize);
reply := messagebox('Move your mouse to the rectangles as fast as you can! Click the form to begin the test.','Information',1);
if (reply=2) then Terminatescript;
SafeInitForm;
SafeShowFormModal;
EndGame;
end.

Flight

2013-06-25 00:02:06

Did this a few times and it crashed my Simba. :( So the higher the score the better or….?

rj

2013-06-25 09:34:21

From: Flight
Did this a few times and it crashed my Simba. :( So the higher the score the better or….?


The higher the reaction time and points per square, points per square is based off reaction time and how big the square is

My simba crashed once I'm not sure what it is