📄 超酷的走迷宫程序_数据结构与算法_数据结构算法_c语言_c 语言之家.htm
字号:
width="100%">
<TBODY>
<TR>
<TD align=middle
background="超酷的走迷宫程序_数据结构与算法_数据结构算法_C语言_C 语言之家.files/002.jpg"
borderColor=#e2ca9f vAlign=top width="69%">
<TABLE align=center border=0 cellPadding=0 cellSpacing=0
width="100%">
<TBODY>
<TR>
<TD height=40 width="100%"></TD></TR>
<TR>
<TD>
<FORM action=Readnews.asp?newsid=4776&id2=4776
method=post name=form1>
<CENTER><!-- <input type=submit name=aa value="点击关闭浮动图标" width=20 title="点击广告支持本站">--></CENTER></FORM></TD></TR>
<TR>
<TD align=middle bgColor=#dddddd height=20
style="FONT-SIZE: 18px" vAlign=bottom
width="85%"><STRONG><FONT color=#003399
size=4><B>超酷的走迷宫程序 </B></FONT></STRONG></TD><BR></TR>
<TR>
<TD align=middle width="100%"><BR></TD></TR>
<TR>
<TD align=middle style="FONT-SIZE: 9pt"
width="100%">发表日期:2004年11月18日 出处:朱清 作者:朱清 已经有761位读者读过此文</TD></TR>
<TR>
<TD align=middle width="100%"><!--下面的这一句是设置阅读文本区的宽度-->
<TABLE align=center border=0 cellPadding=0 cellSpacing=0
style="TABLE-LAYOUT: fixed" width="90%">
<TBODY>
<TR>
<TD align=middle width="100%"></TD></TR>
<TR>
<TD style="WORD-WRAP: break-word"><FONT
class=news><BR>
<P align=center>超酷的走迷宫程序</P>
<P>去年发表的<迷宫探路>系列的Windows版.开发环境:c++builder6 ,
windows2000</P>
<P>全部工程文件和源文件在附件中(需要
Winrar 解压缩),运行效果大致如下图</P>
<P>运行环境: 需要安装c++builder6</P>
<P>算法说明参见去年发表的<迷宫探路>I-IV系列文章.</P>
<P align=center>
<P align=center>
<P align=center><IMG
onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333"
src="超酷的走迷宫程序_数据结构与算法_数据结构算法_C语言_C 语言之家.files/20041115100573562.jpg"></P>
<P>下面是主要源文件 UnitMaze.cpp</P>
<P>另外,本人对单片机感兴趣,有谁知道上海那有便宜的 <FONT
size=2>凌阳科技61板</FONT><FONT size=3>
</FONT>卖,请告诉我.</P>
<P>//作者:朱清 2004-11-18<BR>//Email: <A
href="mailto:cleanzhu2002@yahoo.com.cn">cleanzhu2002@yahoo.com.cn</A><BR>//---------------------------------------------------------------------------</P>
<P>#include <vcl.h><BR>#pragma hdrstop</P>
<P>#include
"UnitMaze.h"<BR>//---------------------------------------------------------------------------<BR>#pragma
package(smart_init)<BR>#pragma resource
"*.dfm"<BR>TForm1
*Form1;<BR>//---------------------------------------------------------------------------<BR>__fastcall
TForm1::TForm1(TComponent*
Owner)<BR>
:
TForm(Owner)<BR>{<BR>}<BR>//---------------------------------------------------------------------------<BR> <BR>struct
pace{<BR> int pre;<BR> int
ri;<BR> int rj;<BR> } ;</P>
<P> int bg[8][8];<BR> int M
;<BR> int N ;<BR> int step
;<BR> int dir ;<BR> int i ;<BR>
int j ;<BR> int x ;<BR> int y
;<BR> int w ;<BR> int h ;<BR>
int count ;<BR> int le ;<BR> pace
road[64] ;<BR> pace bestroad[64] ;<BR>
int runnum ;</P>
<P>void __fastcall TForm1::init(TObject
*Sender)<BR>{<BR>
int i,j;<BR>
for
(i=0;i<8;i++)<BR>
for
(j=0;j<8;j++)<BR>
bg[i][j]=1;<BR>
step=30;<BR>
dir=2;<BR>
M=8;N=8;<BR>
x=5;y=5;<BR>
w=8;h=8;<BR>
setBg();<BR>
//--------<BR>
drawMaze(Sender);<BR>
findShortRoad(Sender);<BR>
count=0;<BR>
runnum=0;<BR>}</P>
<P>void __fastcall TForm1::drawMaze(TObject
*Sender)<BR>{<BR> int i,j;</P>
<P>
//Canvas->Polyline([Point(0,30),Point(0,240),Point(210,240)]);<BR>
//Canvas->Polyline([Point(240,210),Point(240,0),Point(30,0)]);<BR>
Canvas->MoveTo(0,30);<BR>
Canvas->LineTo(0,240);<BR>
Canvas->LineTo(210,240);<BR>
Canvas->MoveTo(240,210);<BR>
Canvas->LineTo(240,0);<BR>
Canvas->LineTo(30,0);<BR> for
(i=0 ;i<=
7;i++)<BR>
for (j=0;j<= 7;j++)
<BR>
{<BR>
if( bg[i][j]==1)
<BR>
{<BR>
Canvas->Brush->Color=clGreen;<BR>
Canvas->Rectangle(j*step,i*step,j*step+step,i*step+step);<BR>
}<BR>
}<BR>}</P>
<P>void __fastcall TForm1::setBg() <BR>//
随机生成代表迷宫地图的数组 /<BR>{<BR>
int i,j ;<BR> int
ran ;<BR> int dir
;<BR> int a,b ;<BR>// 初始化迷宫地图
/<BR>
b=w-1;<BR>
a=h-1;<BR> for( i=0 ;i<=
a;i++)<BR>
for (j=0;j<= b;j++)
<BR>
bg[i][j]=1;</P>
<P>// 随机生成迷宫通路 */<BR>
randomize();<BR>
i=0;j=0;dir=2;<BR> while(true)
<BR>
{<BR>
bg[i][j]=0;<BR>
if((i>=a) && (j>=b))
<BR>
break;<BR>
ran=(int)random(4);<BR>
// dir =0,1,2,3
分别表示上次运动方向:向西,向北,向东,向南.<BR>
if(ran<=2) { //
向南<BR>
if((dir!=1) && (i<a))
//上次运动方向不是向北并且未到南边界<BR>
{<BR>
i=i+1;
//向南运动<BR>
dir=3;<BR>
}<BR>
}
<BR>
/*else if(ran<=2)
{<BR>
if((dir!=2) && (j>0))
<BR>
{<BR>
j=j-1;//向西<BR>
dir=0;<BR>
}<BR>
}<BR>
else if(ran<=3)
{<BR>
if((dir!=3) && (i>0))
<BR>
{<BR>
i=i-1;//向北<BR>
dir=1;<BR>
}<BR> }
*/<BR>
else<BR>
{<BR>
if((dir!=0) && (j<b))
<BR>
{<BR>
j=j+1;//向东<BR>
dir=2;<BR>
}
<BR>
}<BR> }<BR>//
随机生成迷宫其余部分 */<BR> for
(i=0;i<=a;i++)<BR>
for
(j=0;j<=b;j++)<BR>
if(bg[i][j]==1)<BR>
{<BR>
ran=(int)random(10);<BR>
if(ran<4)
<BR>
bg[i][j]=0;<BR>
}<BR>}</P>
<P>void __fastcall TForm1::N2Click(TObject
*Sender)<BR>{<BR>
ClearCanvas(Sender);<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -