| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 898 人关注过本帖
标题:js新手写了一个五子棋程序,可惜无法运行,请高手指教!
只看楼主 加入收藏
过傻过天真
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:0 
js新手写了一个五子棋程序,可惜无法运行,请高手指教!
<html>
<head>
<title>五子棋</title>
<style type="text/css">
td{width:25;
height:25;
color:blue;}
</style>
<script language="JavaScript">
var ma=0;
var xx;
var yy;
function setWhite()
{
  var objEle = document.all.tags("td");
  var i=0;
  var x=document.myform1.mytext1.value;
  var y=document.myform1.mytext2.value;
  i=(x-1)*15+(y-1);
  objEle(i).style.background= "black";
  x--;
  y--;
  main(x,y);
}


function main(x,y)
{
var i;
var qi=new Array(15);
for(i=0;i<15;i++)
qi[i]=new Array(15);
qi[x][y]=1;
weixian(qi);
if(ma>=5)
{
alert("玩家胜!");
}
if(ma<3)
{
heshi(qi);
if(ma>=4)
{
qi[xx][yy]=2;
xia(xx,yy);
alert("电脑胜!");
}
qi[xx][yy]=2;
xia(xx,yy);
ma=0;
}
function weixian(qi)
{
    var a;
    var b=0;
    var c;
    var x;
    var y;
    var i;
    var j;
var aa=new Array(15);
for(i=0;i<15;i++)
aa[i]=new Array(15);
for(i=0;i<15;i++)
for(j=0;j<15;j++)
aa[i][j]=new Array(4);
    for(x=0;x<15;x++)
        for(y=0;y<15;y++)
            if(qi[x][y]==0)
            {
                a=y;
                a++;
                for(;a>=0&&a<=14&&qi[x][a]==1&&a<=y+5;a++)
                    b++;
                    a=y;
                    a--;
                for(;a>=0&&a<=14&&qi[x][a]==1&&a>=y-5;a--)
                    b++;
                aa[x][y][0]=b;
                b=0;
                a=x;
                a++;
                for(;a>=0&&a<=14&&qi[a][y]==1&&a<=x+5;a++)
                    b++;
                    a=x;
                    a--;
                for(;a>=0&&a<=14&&qi[a][y]==1&&a>=x-5;a--)
                    b++;
                aa[x][y][1]=b;
                b=0;
                a=x;
                c=y;
                a++;
                c++;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==1&&a<=x+5;a++,c++)
                    b++;
                    a=x;
                    c=y;
                    a--;
                    c--;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==1&&a>=x-5;a--,c--)
                    b++;
                aa[x][y][2]=b;
                b=0;
                a=x;
                c=y;
                a++;
                c--;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==1&&a<=x+5;a++,c--)
                    b++;
                    a=x;
                    c=y;
                    a--;
                    c++;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==1&&a>=x-5;a--,c++)
                    b++;
                aa[x][y][3]=b;
                b=0;
                for(i=0;i<4;i++)
                    if(aa[x][y][i]>=ma)
                    {
                        ma=aa[x][y][i];
                        xx=x;
                        yy=y;
                    }
            }
}
function heshi(qi)
{
    var a;
    var b=0;
    var c;
    var x;
    var y;
    var i;
    var j;
var aa=new Array(15);
for(i=0;i<15;i++)
aa[i]=new Array(15);
for(i=0;i<15;i++)
for(j=0;j<15;j++)
aa[i][j]=new Array(4);
    for(x=0;x<15;x++)
        for(y=0;y<15;y++)
            if(qi[x][y]==0)
            {
                a=y;
                a++;
                for(;a>=0&&a<=14&&qi[x][a]==2&&a<=y+5;a++)
                    b++;
                    a=y;
                    a--;
                for(;a>=0&&a<=14&&qi[x][a]==2&&a>=y-5;a--)
                    b++;
                aa[x][y][0]=b;
                b=0;
                a=x;
                a++;
                for(;a>=0&&a<=14&&qi[a][y]==2&&a<=x+5;a++)
                    b++;
                    a=x;
                    a--;
                for(;a>=0&&a<=14&&qi[a][y]==2&&a>=x-5;a--)
                    b++;
                aa[x][y][1]=b;
                b=0;
                a=x;
                c=y;
                a++;
                c++;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==2&&a<=x+5;a++,c++)
                    b++;
                    a=x;
                    c=y;
                    a--;
                    c--;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==2&&a>=x-5;a--,c--)
                    b++;
                aa[x][y][2]=b;
                b=0;
                a=x;
                c=y;
                a++;
                c--;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==2&&a<=x+5;a++,c--)
                    b++;
                    a=x;
                    c=y;
                    a--;
                    c++;
                for(;a>=0&&a<=14&&c>=0&&c<=14&&qi[a][c]==2&&a>=x-5;a--,c++)
                    b++;
                aa[x][y][3]=b;
                b=0;
                for(i=0;i<4;i++)
                    if(aa[x][y][i]>=ma)
                    {
                        ma=aa[x][y][i];
                        xx=x;
                        yy=y;
                    }
            }
}
function xia(x,y)
{
var i;
var objEle = document.all.tags("td");
x++;
y++;
i=(x-1)*15+(y-1);
  objEle(i).style.background= "red";
}
</script>
</head>
<body>
<center>
<h2>五子棋</h2>
<hr>
<form name="myform1">
横行:<input type="text" name="mytext1" width="80">&nbsp;&nbsp;
竖列:<input type="text" name="mytext2" width="80">&nbsp;&nbsp;
<input type="button" onClick="setWhite()" value="提交">
</form>
<table width="450" height="450" border="1">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    <td>6</td>
    <td>7</td>
    <td>8</td>
    <td>9</td>
    <td>10</td>
    <td>11</td>
    <td>12</td>
    <td>13</td>
    <td>14</td>
    <td>15</td>
  </tr>
  <tr>
    <td>2</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>3</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>4</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>5</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>6</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>7</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>8</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>9</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>10</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>11</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>12</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>13</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>14</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>15</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
</center>
</body>
</html>

[[it] 本帖最后由 过傻过天真 于 2008-6-1 20:07 编辑 [/it]]
搜索更多相关主题的帖子: 五子棋 指教 运行 
2008-06-01 20:01
快速回复:js新手写了一个五子棋程序,可惜无法运行,请高手指教!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.132266 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved