我作的只有九格的,不过你可以自己改制成任意多格的迷宫.前提是一定要是用我的6个css样式来布局迷宫.否则会出错.核心的javascript我已经测试过了.没有问题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<title>无标题文档</title>
<style>
.rb{
border-style:double
border-width:0px
border-color:#000000
border-left-width:1px
border-top-width:1px
}
.rt{
border-style:double
border-width:0px
border-color:#000000
border-left-width:1px
border-bottom-width:1px
}
.lb{
border-style:double
border-width:0px
border-color:#000000
border-right-width:1px
border-top-width:1px
}
.lt
{
border-style:double
border-width:0px
border-color:#000000
border-right-width:1px
border-bottom-width:1px
}
.lr{
border-style:double
border-width:0px
border-color:#000000
border-top-width:1px
border-bottom-width:1px
}
.tb
{
border-style:double
border-width:0px
border-color:#000000
border-left-width:1px
border-right-width:1px
}
</style>
</head>
<body>
<div id="layer1" style="position:absoluteleft:15pxtop:21pxwidth:27pxheight:29pxz-index:1background-color: #FF0000layer-background-color: #FF0000border: 1px none #000000"></div>
<table width="120" height="120" border="0" cellpadding="0" cellspacing="0" style="border-color:#000000border-width:1pxborder-style:solid">
<tr>
<td class="rb"> </td>
<td class="rb"> </td>
<td class="lb"> </td>
</tr>
<tr>
<td class="tb"> </td>
<td class="rt"> </td>
<td class="lb"> </td>
</tr>
<tr>
<td class="rt"> </td>
<td class="lr"> </td>
<td class="lt"> </td>
</tr>
</table>
<script language="javascript">
//得用css来布局迷宫,迷宫的多少行多少列,只要改下面的数据就可以了.不过表格的单元格一定要是40*40
var col=3//列数
var row=3//行数
var i=0//位置数
var player=document.getElementById("layer1")
var td=document.getElementsByTagName("table")[0].getElementsByTagName("td")
document.onkeydown=function (e)
{
e=window.event||e
if(e.keyCode==37)//向下运动
{
if(i%col!=0)//不在最左边
{
if((td[i].className=="lb"||td[i].className=="lt"||td[i].className=="lr")&&(td[i-1].className=="rb"||td[i-1].className=="rt"||td[i-1].className=="lr"))//可以通过
{
player.style.left=parseInt(player.style.left)-40+"px"
i=i-1
}
}
}//向左运动
else if(e.keyCode==38)//向上运动
{
if(i>=col)//不在最上边
{
if((td[i].className=="lt"||td[i].className=="rt"||td[i].className=="tb")&&(td[i-col].className=="tb"||td[i-col].className=="rb"||td[i-col].className=="lb"))//可以通过
{
player.style.top=parseInt(player.style.top)-40+"px"
i=i-col
}
}
}//向上运动
else if(e.keyCode==39)//向右运动
{
if((i%col)!=(col-1))//不在最右边
{
if((td[i].className=="lr"||td[i].className=="rt"||td[i].className=="rb")&&(td[i+1].className=="lb"||td[i+1].className=="lt"||td[i+1].className=="lr"))//可以通过
{
player.style.left=parseInt(player.style.left)+40+"px"
i=i+1
}
}
}//向右运动
else if(e.keyCode==40)//向下运动
{
if(i<=col*(row-1))//不在最下边
{
if((td[i].className=="lb"||td[i].className=="rb"||td[i].className=="tb")&&(td[i+col].className=="tb"||td[i+col].className=="rt"||td[i+col].className=="lt"))//可以通过
{
player.style.top=parseInt(player.style.top)+40+"px"
i=i+col
}
}
}//向下运动
}
</script>
</body></html>
typedef struct{int Col,Row//迷宫的大小
int arr[Rangle][Rangle]//0表示障碍,1表示是可走的通道,-1表示外界的围墙
}MazeType
void InitMaze(MazeType
&M,int col,int row)
{
//按照用户的输入的行数row和列数col列的二维数组(元素值为1或0)
//设置迷宫的初值,加上边缘的一圈的值
}
void PrintMaze(MazeType M)
{
//根据已经进行二维数组的标记值来输出迷宫(或者其通路)
}
bool Pass(MazeType M,PosType pos)
{//求解迷宫M中,从Start到end的一条路径
//若存在则返回true,否则返回false
Stack S
InitStack(S)
PosType curpos=start//设置当前坐标为入口位置;
int curstep=1
//当前的步数
bool Find=false
//是否找到出口
ElemType e
do{
if(Pass(M,curpos))
{
FootPrint(M,curpos)//在当前位置标记为2
e.step=1
e.seat=curpos
e.di=1//初始化为向右边位置移动
Push(S,e)
if(curpos.c==end.c&&curpos.r==end.r)//如果找到了出口则终止,并返回true
{
Find=true
return Find
}
else{
curpos=NextPos(curpos,1)
curstep++
}
}
else{//当前位置不能通过
if(!StackEmpty(S)){
Pop(S,e)//将已经走过的最近位置弹出,数据保存在e中
while(e.di==4&&!(StackEmpty(S))){
MarkPrint(M,e.seat)//留下不能通过的标记
Pop(S,e)
curstep--
}//while
if(e.di<4)//不能通过则改变方向
{
e.di++//方向顺时针改变一下
Push(S,e)
curpos = NextPos(e.seat,e.di) //求下一个节点
}
}
}
}while(!StackEmpty(S)&&!Find)
//(!StackEmpty(S)&&!Find)//当栈不为空且没有找到出口
return
false//没有找到出口则返回false
<html><head>
<meta http-equiv="Content-type" content="text/htmlcharset=utf-8">
<title>远程网页源代码读取</title>
<style type="text/css">
/* 页面字体样式 */
body, td, input, textarea {
font-family:Arial
font-size:12px
}
</style>
<script type="text/javascript">
//用于创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest() //FireFox、Opera等浏览器支持的创建方式
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")//IE浏览器支持的创建方式
}
}
//直接通过XMLHttpRequest对象获取远程网页源代码
function getSource() {
var url = document.getElementById("url").value//获取目标地址信息
//地址为空时提示用户输入
if (url == "") {
alert("请输入网页地址。")
return
}
document.getElementById("source").value = "正在加载……" //提示正在加载
createXmlHttp() //创建XMLHttpRequest对象
xmlHttp.onreadystatechange = writeSource //设置回调函数
xmlHttp.open("GET", url, true)
xmlHttp.send(null)
}
//将远程网页源代码写入页面文字区域
function writeSource() {
if (xmlHttp.readyState == 4) {
document.getElementById("source").value = xmlHttp.responseText
}
}
</script>
</head>
<body>
<h1>远程网页源代码读取</h1>
<div>
地址:<input type="text" id="url">
<input type="button" onclick="getSource()" value="获取源码">
</div>
<textarea rows="10" cols="80" id="source"></textarea>
</body>
</html>
我也是别人那抄的 你试试吧 好的话给我个最佳