87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>BinGo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style rel="stylesheet" type="text/css">
td{
padding: 10px;
text-align: center;
width: 20%;
font-size:50px;
}
table{
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="background:lightblue;text-align:center;" border="2" align="center" height="500" width="500">
<tr>
<td onclick="checkWin(this)" no="11" id="r11">1</td>
<td onclick="checkWin(this)" no="12" id="r12">1</td>
<td onclick="checkWin(this)" no="13" id="r13">1</td>
<td onclick="checkWin(this)" no="14" id="r14">1</td>
<td onclick="checkWin(this)" no="15" id="r15">1</td>
</tr>
<tr>
<td onclick="checkWin(this)" no="21" id="r21">1</td>
<td onclick="checkWin(this)" no="22" id="r22">1</td>
<td onclick="checkWin(this)" no="23" id="r23">1</td>
<td onclick="checkWin(this)" no="24" id="r24">1</td>
<td onclick="checkWin(this)" no="25" id="r25">1</td>
</tr>
<tr>
<td onclick="checkWin(this)" no="31" id="r31">1</td>
<td onclick="checkWin(this)" no="32" id="r32">1</td>
<td onclick="checkWin(this)" no="33" id="r33" style="color:green;">F</td>
<td onclick="checkWin(this)" no="34" id="r34">1</td>
<td onclick="checkWin(this)" no="35" id="r35">1</td>
</tr>
<tr>
<td onclick="checkWin(this)" no="41" id="r41">1</td>
<td onclick="checkWin(this)" no="42" id="r42">1</td>
<td onclick="checkWin(this)" no="43" id="r43">1</td>
<td onclick="checkWin(this)" no="44" id="r44">1</td>
<td onclick="checkWin(this)" no="45" id="r45">1</td>
</tr>
<tr>
<td onclick="checkWin(this)" no="51" id="r51">1</td>
<td onclick="checkWin(this)" no="52" id="r52">1</td>
<td onclick="checkWin(this)" no="53" id="r53">1</td>
<td onclick="checkWin(this)" no="54" id="r54">1</td>
<td onclick="checkWin(this)" no="55" id="r55">1</td>
</tr>
</table>
<a href="1.htm" onClick="location.reload;">单击此处,刷新</a>
</body>
<script type="text/javascript" language="javascript" src="1.js">
</script>
</html>
/*
* id:是标签的id
* bgNoArr:是一列的数组
* cNo:行号
**/
//有效的选中次数
var isClick=0;
//保存Bingo中产生的随机数
var bgNoArr = Array(5);
init();
function init()
{
//alert("准备开始");
try{
//重复5次,把5组 td数组写入内容
//x是次数 、 列号
nWrite();
}
catch(errMsg)
{
alert("出现错误\n"+errMsg.message);
}
//alert("结束!!!");
}
function nWrite()
{
bgNoArr = Array(5);
//把没有重复的数组拿出来,再根据行号cNo写入表格
var id;
for(var i =1;i<6;i++)
{
bgNoArr = find(i);
for(var x =1;x<6;x++)
{
// id="r15"
// id="r21"
if(""+x+i=="33")
{
//中央的Free不输出
continue;
}
id = "r"+ x + i;//r + 列号 + 列排名 r?1
//alert("id:"+id);
var o = document.getElementById(id);
o.innerHTML = bgNoArr[x];
}
}
}
function getArr(cNo)
{
bgNoArr = Array(5);
for(var x=1;x<6;x++)
{
bgNoArr[x] = getNo(cNo);
}
return bgNoArr;
}
function find(cNo)
{
bgNoArr = Array(5);
bgNoArr = getArr(cNo);
var aa=5;
for(var x=0;x<6;x++)
{
for(var j=0;j<6;j++)
{
if(bgNoArr[j] == bgNoArr[x])
{
while(aa--){
if(bgNoArr[j] != bgNoArr[aa+1])
bgNoArr[j]=getNo(cNo);//alert(bgNoArr[j]+" : "+bgNoArr[j]+"出现重复");
}aa=5;
}
}
}
return bgNoArr;
}
function getNo(cNo)
{
switch(cNo)
{
case 1:
{
cNo = 15;
break;
}
case 2:
{
cNo = 30;
break;
}
case 3:
{
cNo = 45;
break;
}
case 4:
{
cNo = 60;
break;
}
case 5:
{
cNo = 75;
break;
}
default:alert("switch出错了!!");
}
var n;
n = Math.random();
n=n*10;
n = cNo - Math.floor(n);
return n;
}
function checkWin(td)
{
var element = td;
var color = td.style.background;
if(color != "red")
{
td.style.background="red";
isClick++;
}
else
{
td.style.background = "lightblue";
isClick--;
}
//如果 有效的点击超过了4个就开始判断
if(isClick>4)
{
wasClick();
}
}
function wasClick()
{
//把表格中 被选中的格子 依据下标写入数组中对应的位置
var count= new Array([0,0,0,0,0,0],[0,0,0,0,0,0]);
var td;
var id;
//判断count 是否 横 或者 竖 或者 对角线 有5个格子的都被选中
var isWin=0;
for(var i=1;i<6;i++)
{
for(var j=1;j<6;j++)
{
id = "r"+ i + j;
td = document.getElementById(id);
if(td.style.background == "red")
{
count[i][j] = 1;
}//alert("i:"+i+"\nj:"+j);
}
}
for(var i=0;i<5;i++)
{
for(var j=0;j<5;j++)
{
if(count[i][j] == count[j][i]|| count[i][j] == count[i-1][j-1])
{
isWin++;
}
}
}
if(isWin==5)
{
alert("Bingo!!");
}
else
{
alert("点击了"+isClick+"\niswin:"+isWin);
}
}