计数错误,一定是你的list只有2,你却访问了string[2]之类的造成的!一般strings是从0开始的。所以:
for i:=0 to listbox1.items.count-1 do
.....
for i:=0 to listbox1.items.count-1 do
.....
解决方案 »
- 请教TcpServer1.Accept接受问题!如何使用ClientSocket.ReceiveBuf()显示啊在线等
- 在这临近年关的时候,我不祝福大家新年快乐,请大家进来缅怀已经离去1周年的sysu死树前辈!
- (300分)有没有画图方面的行家在线?关于定位的精确问题。在线等,比较急的..
- 为何下载的DELPHI源代码不能编译运行?
- 对TCanvas的Draw方法的疑问,进来看看吧!~你的回复伴随着一个菜鸟的成长~~~
- 在先等待,急!请进来看详细内容
- 非常急的问题---请问DCOM能否通过Internet进行远程调用的!
- 关于Delphi7的问题
- 可以用 WinExeC 同时打开两个文件吗? 不行的话,该怎样呢?
- ie5.5何处有当, microsoft的下载中心不行还有2000下的五笔字型
- 我是菜鸟,请教在那里创建存储过程?如何创建?(敬请举例)
- DATABASE,代码值显示
程序中,for i:=1 to 14 do
for j:=1 to 16 do后来根据大虾指点进行了若干次修改,还不行
第一次修改:将二维数组定义为box[1..15,1..17]还报同样的错
第二次修改:将二维数组定义为box[0..14,0..16],
程序中, for i:=0 to 13 do
for J:=0 to 15 do
还报同样的错
第三次修改:将二维数组定义为box[0..15,0..17]
程序中,for i:=1 to 14 do
for j:=1 to 16 do
还报同样的错
第四次修改:将二维数组定义为box[0..14,0..16]
程序中,for i:=0 to 13 do
for j:=0 to 15 do
还报同样的错
第四次修改:将二维数组定义为box[0..14,0..16]
程序中,for i:=1 to 13 do
for j:=1 to 15 do
程序虽然不报错,但我需要的是14*16的数组,运行结果不对总之,i的取值只能是1..13,j的取值只能是1..15,可我需要14*16的数组!
高手指点!
for I:=Low(box) to High(box) do // 一维的下标到上标;
for J:=Low(box[i]) to High(box[i]) do // 二维的下标到上标;
.........
var box:array[0..13,0..15] of integer;
i,j:integer;
begin
for i:=0 to 13 do
for j:=0 to 15 do
box[i,j]:=0;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Menus, ComCtrls,inifiles,shellapi,mmsystem;type
boxbase=array [0..13,0..15] of integer;
TForm1 = class(TForm)
black: TImage;
boxok: TImage;
diban: TImage;
pushd1: TImage;
pushd2: TImage;
pushl1: TImage;
pushl2: TImage;
pushr1: TImage;
pushr2: TImage;
pushu2: TImage;
qiang: TImage;
rbox: TImage;
ybox: TImage;
MainMenu1: TMainMenu;
Timer1: TTimer;
StatusBar1: TStatusBar;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
pushu1: TImage;
bkground: TImage;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
// procedure N4Click(Sender: TObject);
// procedure N5Click(Sender: TObject);
// procedure N1Click(Sender: TObject);
// procedure N9Click(Sender: TObject);
// procedure N7Click(Sender: TObject);
private
{ Private declarations }
procedure drawimage(argx,argy,argimage:integer);
function readfile:integer;
procedure drawbkground;
public
{ Public declarations }
lastx,lasty:integer;
localx,localy:integer;
ifmove:boolean;
comdir:string;
filenum:integer;
box:boxbase;
boxnum:integer;
boxini:tinifile;
steps:integer;
//soundflag:boolean;
end;var
Form1: TForm1;implementation
{$R *.DFM}procedure tform1.drawbkground; //背景
var i,j:integer;
begin
timer1.enabled:=false;
for i:=0 to 13 do
for j:=0 to 15 do
drawimage(i,j,box[i][j]);
timer1.enabled:=true;
end; procedure tform1.drawimage(argx,argy,argimage:integer);
var comimage:timage;
begin
case argimage of
0:comimage:=form1.black;
1:comimage:=form1.qiang;
2:comimage:=form1.diban;
3:comimage:=form1.ybox;
4:comimage:=form1.boxok;
7:comimage:=form1.rbox;
51,61:comimage:=form1.pushu1;
52,62:comimage:=form1.pushu2;
53,63:comimage:=form1.pushl1;
54,64:comimage:=form1.pushl2;
55,65:comimage:=form1.pushr1;
56,66:comimage:=form1.pushr2;
57,67:comimage:=form1.pushd1;
58,68:comimage:=form1.pushd2;
else
exit;
end;
form1.bkground.canvas.copyrect(rect((argy-1)*30,
(argx-1)*30,argy*30,argx*30),
comimage.canvas,rect(0,0,30,30))
end; function tform1.readfile:integer;
var filehandle:file of integer;
i,j,fsize,funre:integer;
filename:string;
begin
funre:=1;
steps:=0;
filename:=comdir+'\bbk\box'+inttostr(filenum)+'.bbk';
if (not fileexists(filename)) then
if filenum=1 then
funre:=0
else
begin
filenum:=1;
filename:=comdir+'\bbk\box1.bbk';
if not fileexists(filename) then
funre:=0;
end;
if funre<>0 then
begin
boxnum:=0;
assignfile(filehandle,filename);
reset(filehandle);
fsize:=filesize(filehandle);
if fsize<>224 then
funre:=0
else
begin
form1.caption:='推箱子现在你推的是'+inttostr(filenum)+'关';
for i:=0 to 13 do
for j:=0 to 15 do
begin
read(filehandle,box[i][j]);
if (box[i][j]=57) or (box[i][j]=58) then
begin localx:=i;localy:=j;end;
if (box[i][j]=3) then
boxnum:=boxnum+1;
end;
end;
closefile(filehandle);
end
else
filenum:=0;
readfile:=funre;
end;
procedure TForm1.FormCreate(Sender: TObject);
var result,i,j:integer;
begin
timer1.enabled:=false;
for i:=0 to 13 do
for j:=0 to 15 do
box[i][j]:=0;
drawbkground;
form1.width:=488;
getdir(0,comdir);
if comdir[strlen(pchar(comdir))]='\' then
comdir[strlen(pchar(comdir))]:=' ';
comdir:=trimright(comdir);
lastx:=0;lasty:=0;
localx:=0;localy:=0;
boxini:=tinifile.create(comdir+'\box.ini');
filenum:=boxini.readinteger('score','lastscore',0);
//soundflag:=boxini.readbool('sound','sound',true);
//n8.checked:=soundflag;
result:=readfile;
if result=0 then
begin
showmessage('没有可以过的关');
filenum:=0;
end
else
begin
drawbkground;
form1.caption:='推箱子 现在你推的是'+inttostr(filenum)+'关';
timer1.enabled:=true;
end;
end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var bestmove,xflag,yflag:integer;
begin
case key of
37:begin
xflag:=0;
yflag:=-1;
end;
38:begin
xflag:=-1;
yflag:=0;
end;
39:begin
xflag:=0;
yflag:=1;
end;
40:begin
xflag:=1;
yflag:=0;
end;
else
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\nomove.wav'),snd_async);
exit;
end;
case box[localx+xflag][localy+yflag] of
2:begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag][localy+yflag]:=54+3*xflag+yflag;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=false;
end;
4:begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag][localy+yflag]:=64+3*xflag+yflag;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=false;
end;
3:case box[localx+xflag+xflag][localy+yflag+yflag] of
2:begin
//if soundflag then
// sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag+xflag][localy+yflag+yflag]:=3;
box[localx+xflag][localy+yflag]:=54+3*xflag+yflag;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=true;
end;
4:begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag+xflag][localy+yflag+yflag]:=7;
box[localx+xflag][localy+yflag]:=54+3*xflag+yflag;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=true;
end;
else
// begin
// if soundflag then
//sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
exit;
//end;
end;
7:case box[localx+xflag+xflag][localy+yflag+yflag] of
2:begin
// if soundflag then
//sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag+xflag][localy+yflag+yflag]:=3;
box[localx+xflag][localy+yflag]:=64+3*xflag+yflag;
boxnum:=boxnum+1;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=true;
end;
4:begin
//if soundflag then
// sndplaysound(pchar(comdir+'\sound\move.wav'),snd_async);
box[localx+xflag+xflag][localy+yflag+yflag]:=7;
box[localx+xflag][localy+yflag]:=64+3*xflag+yflag;
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
ifmove:=true;
end;
else
//begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\nomove.wav'),snd_async);
exit;
//end;
end;
else
//begin
// if soundflag then
// sndplaysound(pchar(comdir+'\sound\nomove.wav'),snd_async);
exit;
//end;
end;
lastx:=localx;
lasty:=localy;
localx:=localx+xflag;
localy:=localy+yflag;
timer1.enabled:=false;
steps:=steps+1;
statusbar1.panels[1].text:='你的移动步数为'+inttostr(steps);
drawbkground;
if (boxnum=0) then
begin
//if soundflag then
// sndplaysound(pchar(comdir+'\sound\over.wav'),snd_async);
bestmove:=boxini.readinteger('box','box'+inttostr(filenum),0);
if (steps<bestmove) or (bestmove=0) then
begin
boxini.writeinteger('box','box'+inttostr(filenum),steps);
showmessage('你做得太好了,我佩服你,多努力!');
end
else
showmessage('你还要多锻炼锻炼!只是时间问题!');
steps:=0;
statusbar1.panels[1].text:='你移动的步数为'+inttostr(steps);
filenum:=filenum+1;
lastx:=0;lasty:=0;
localx:=0;localy:=0;
readfile;
drawbkground;
end;
timer1.enabled:=true;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var comimage:timage;
begin
timer1.enabled:=false;
case box[localx][localy] of
51,61:comimage:=pushr2;
52,62:comimage:=pushr1;
53,63:comimage:=pushl2;
54,64:comimage:=pushl1;
55,65:comimage:=pushu2;
56,66:comimage:=pushu1;
57,67:comimage:=pushd2;
58,68:comimage:=pushd1;
else
exit;
end;
if (box[localx][localy] mod 2)=0 then
box[localx][localy]:=box[localx][localy]-1
else
box[localx][localy]:=box[localx][localy]+1;
bkground.canvas.copyrect(rect(localy*30-30,localx*30-30,localy*30,localx*30),
comimage.canvas,rect(0,0,30,30));
timer1.enabled:=true;
end;{procedure TForm1.N4Click(Sender: TObject);
var i,j:integer;
begin
//if soundflag then
// sndplaysound(pchar(comdir+'\sound\backbox.wav'),snd_async);
steps:=steps-1;
statusbar1.Panels[1].text:= '你的移动步数为'+inttostr(steps);
case box[lastx][lasty] of
2:box[lastx][lasty]:=57;
4:box[lastx][lasty]:=67;
end;
if ifmove then
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=3;
61,62,63,64,65,66,67,68:box[localx][localy]:=7;
end
else
case box[localx][localy] of
51,52,53,54,55,56,57,58:box[localx][localy]:=2;
61,62,63,64,65,66,67,68:box[localx][localy]:=4;
end;
if(lastx=localx) and (lasty=localy-1) then
begin
if ifmove then
case box[localx][localy+1] of
7:box[localx][localy+1]:=4;
3:box[localx][localy+1]:=2;
end;
end;
if (lastx=localx) and (lasty=localy+1) then
begin
if ifmove then
begin
case box[localx][localy-1] of
7:box[localx][localy-1]:=4;
3:box[localx][localy-1]:=2;
end;
end;
if(lastx=localx+1) and (lasty=localy) then
begin
if ifmove then
case box[localx-1][localy] of
7:box[localx][localy-1]:=4;
3:box[localx][localy-1]:=2;
end;
end;
localx:=lastx;
localy:=lasty;
lastx:=0;
lasty:=0;
boxnum:=0;
for i:=1 to 14 do
for j:=1 to 16 do
if (box[i][j]=3) then
boxnum:=boxnum+1;
drawbkground;
end;
end;
procedure tform1.N5Click(Sender: TObject);
begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\retry.wav'),SND_async);
steps:=0;
statusbar1.Panels[1].text:='你的移动步数为'+inttostr(steps);
lastx:=0;lasty:=0;
localx:=0;localy:=0;
readfile;
drawbkground;
end;procedure TForm1.N1Click(Sender: TObject);
begin
//if soundflag then
//sndplaysound(pchar(comdir+'\sound\click.wav'),snd_async);
n4.enabled:=false;
n5.enabled:=true;
if lastx<>0 then
n4.enabled:=true;
end;procedure TForm1.N9Click(Sender: TObject);
begin
shellexecute(application.handle,pchar('open'),pchar('winhlp32.exe'),
pchar('box.hlp'),pchar(comdir),sw_show);
end;procedure TForm1.N7Click(Sender: TObject);
begin
boxini.writeinteger('score','lastscore',filenum);
//boxini.writebool('sound','sound',soundflag);
boxini.Destroy;
end; }end.