我贴出 这个 函数的代码,是一个我想玩的游戏
procedure TForm1.onclick(Sender: TObject);
var
mapfile:TextFile ;
cmark : shortstring;
mapln : shortstring;
sigchar:shortstring;
i,j:integer;
vmpath : string;
begin
try
if not opendia.Execute then
begin
showmessage('无文件调入!');
sbar1.SimpleText:='无文件调入!';
exit;
end
else
begin
sbar1.SimpleText:='正在打开文件...';
assignfile(mapfile,opendia.filename);
reset(mapfile);
end;
readln(mapfile,cmark);
if cmark<>omark then
begin
closefile(mapfile);
showmessage('不可识别的地图文件!');
sbar1.SimpleText:='不可识别的地图文件!' ;
end
else
sbar1.SimpleText:='正在读取地图数据...';
readln(mapfile,vmpath);
readln(mapfile,mapcaption);
for i:= 0 to 21 do
begin
readln(mapfile,mapln);
for j:=0 to 26 do
begin
sigchar:=midstr(mapln,j,1);
map[j]:=strtoint(sigchar);
end;
end;
sbar1.SimpleText:='正在读取超人与对手数据...';
readln(mapfile,sigchar);
Bomber_Array_sxPos:=strtoint(sigchar);
readln(mapfile,sigchar);
Bomber_Array_syPos:=strtoint(sigchar);
Bomber_Array_oxPos:=Bomber_Array_sxPos;
Bomber_Array_oyPos:=Bomber_Array_syPos;
Bomber_img.Left := Bomber_Array_sxPos*24 ;
Bomber_img.Top := Bomber_Array_syPos*24;
readln(mapfile,sigchar);
if strtoint(sigchar)>6 then
sigchar:='6';
Setlength(Enemy_Array_sxPos,strtoint(sigchar));
Setlength(Enemy_Array_syPos,strtoint(sigchar));
enemycount:=strtoint(sigchar);
for i:= 1 to strtoint(sigchar) do
begin
readln(mapfile,mapln);
Enemy_Array_sxPos:=strtoint(mapln);
Enemyimg.Left:=Enemy_Array_sxPos*24 ;
readln(mapfile,mapln);
Enemy_Array_syPos:=strtoint(mapln);
Enemyimg.Top:=Enemy_Array_syPos*24 ;
end;
closefile(mapfile);
sbar1.SimpleText:='正在打开地图映射文件';
if not fileExists(vmpath) then
begin
showmessage('地图映射文件不存在');
sbar1.SimpleText:='地图映射文件不存在';
exit;
end
else
bk_img.Picture.LoadFromFile(vmpath);
for i:=1 to 6 do
begin
Enemyimg.Enabled:=true;
Enemyimg.Visible:=true;
end;
bomber_img.Visible:=true;
bomber_img.Enabled:=true;
showmessage('文件打开成功,数据处理完成!');//[red]这里出错[/red]
timer1.enabled:=false;
except
closefile(mapfile);
showmessage('文件打开时发生未知错误');
sbar1.SimpleText:='文件打开时发生未知错误';
form1.FormCreate (form1);
end;
end;