perhaps you will find this a little more useful.
TGameFunction can be any parameters you need to send, a record might be easiest.
if a game function requires you to exit the loop it only needs to return a True. in this way you can exit the loop gracefully instead of brute force.
Code:
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,SysUtils
{ you can add units after this };
{$R *.res}
Type
TMessage = record
x,y:Integer;
end;
TGameFunction= Function(vMessage:TMessage):Boolean;
TGameArray=Array of TGameFunction;
Function MoveForward(vMessage:TMessage):Boolean;
begin
result:=False;
end;
Function MoveBack(vMessage:TMessage):Boolean;
begin
result:=False;
end;
Function MoveTurnLeft(vMessage:TMessage):Boolean;
begin
result:=False;
end;
Function MoveTurnRight(vMessage:TMessage):Boolean;
begin
result:=False;
end;
Function ShowMenu(vMessage:TMessage):Boolean;
begin
result:=True;
end;
Var
GameArray:TGameArray;
Message:TMessage;
i,Count:Integer;
begin
Message.x:=10;
Message.y:=10;;
Count:=5;
SetLength(GameArray,Count);
GameArray[0]:=@MoveBack;
GameArray[1]:=@MoveForward;
GameArray[2]:=@MoveTurnLeft;
GameArray[3]:=@MoveTurnRight;
GameArray[4]:=@ShowMenu;
i:=0;
While True do
begin
if GameArray[i](Message) then break;
Inc(i);
sleep(100);
end;
end.
Bookmarks