delphi 怪物有0..20只不等 遍历怪物坐标 假设怪物1坐标 444 怪物2坐标555 怪物3坐标 560 怪物4坐标666
答案:2 悬赏:0
解决时间 2021-03-08 07:20
- 提问者网友:喜遇你
- 2021-03-07 22:10
delphi 怪物有0..20只不等 遍历怪物坐标 假设怪物1坐标 444 怪物2坐标555 怪物3坐标 560 怪物4坐标666 我要取最中间这个怪物的坐标 请问 怎么算法 最好给个算法和实例 谢谢各位朋友 小弟数学不好
最佳答案
- 二级知识专家网友:duile
- 2021-03-07 22:39
你的坐标怎么不是用一个点来表示,难道它们都在一条线上?如果都在一条线上的话,处理方法:
1、找到最左边和最右边的怪物位置
var
LeftP, RightP: Integer;
I: Integer;
begin
for I := 1 to 20 do
begin
LeftP := Min(GuaiWu[I - 1], GuaiWu[I]);
RightP := Max(GuaiWu[I - 1], GuaiWu[I]);
end;
end;
2、找到怪物的中间点
var
MiddleP: Integer;
begin
MiddleP := Abs(RightP - LeftP) div 2;
end;
3、找离中间点最近的怪物
var
I: Integer;
begin
Result := GuaiWu[0];
for I := 1 to 20 do
begin
if Abs(MiddleP - Result) > Abs(MiddleP - GuaiWu[I]) then
begin
Result := GuaiWu[I];
end;
end;
end;
1、找到最左边和最右边的怪物位置
var
LeftP, RightP: Integer;
I: Integer;
begin
for I := 1 to 20 do
begin
LeftP := Min(GuaiWu[I - 1], GuaiWu[I]);
RightP := Max(GuaiWu[I - 1], GuaiWu[I]);
end;
end;
2、找到怪物的中间点
var
MiddleP: Integer;
begin
MiddleP := Abs(RightP - LeftP) div 2;
end;
3、找离中间点最近的怪物
var
I: Integer;
begin
Result := GuaiWu[0];
for I := 1 to 20 do
begin
if Abs(MiddleP - Result) > Abs(MiddleP - GuaiWu[I]) then
begin
Result := GuaiWu[I];
end;
end;
end;
全部回答
- 1楼网友:山鬼偶尔也合群
- 2021-03-08 00:18
函数参数:
path:string 需要遍历的目录 makefilelist( 'e:\,'.exe') ;
fileext:string 要遍历的文件扩展名makefilelist( 'e:\,'.*') ;
function makefilelist(path,fileext:string):tstringlist ;
var
sch:tsearchrec;
begin
result:=tstringlist.create;
if rightstr(trim(path), 1) <> '\' then
path := trim(path) + '\'
else
path := trim(path);
if not directoryexists(path) then
begin
result.clear;
exit;
end;
if findfirst(path + '*', faanyfile, sch) = 0 then
begin
repeat
application.processmessages;
if ((sch.name = '.') or (sch.name = '..')) then continue;
if directoryexists(path+sch.name) then
begin
result.addstrings(makefilelist(path+sch.name,fileext));
end
else
begin
if (uppercase(extractfileext(path+sch.name)) = uppercase(fileext)) or (fileext='.*') then
result.add(path+sch.name);
end;
until findnext(sch) <> 0;
sysutils.findclose(sch);
end;
end;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯