>
设为首页
>
收藏本站
>
最新电影
首页
运营资讯
今日英语
图形图像
计算机技术
Asp编程
网站结构化
资源共享
休闲娱乐
访问新站
您现在的位置:
首页
=>
后台技术
=>
脚本特效
=>
游戏娱乐
订阅本栏目
经典游戏 扫雷
时间: 2007-10-05 13:29:06 阅读次数:1912
<html> <head> <title>网页特效|www.ffasp.com 飞飞Asp乐园|---经典游戏 扫雷 </title> </head><BODY onLoad="startNewGame()"> <!-- 用<BODY onLoad="startNewGame()">替换原有的<body> --> <!--将以下代码加入HTML的<Body></Body>之间--> <script language="JavaScript"> <!-- hide code from old browsers var BOMB = " * "; var NOBOMB = ""; var MARKED = " X "; var constModul = 0.0; var constFactor = 0.0; var constMove = 0.0; var pseudoRandomNumber = 0.0; var constXSize = 5; var constYSize = 5; var constBombAmnt = 5; var squaresCleared = 0; var firstTime=false; var topValue=-1; var rightValue=-1; var bottomValue=-1; var leftValue=-1; var array; var startTime; var timerID = null; var timerRunning = false; //-------------------------------------------------------------------------- function stopClock (){ if(timerRunning) clearTimeout(timerID); timerRunning = false; } //-------------------------------------------------------------------------- function startClock (){ // Make sure the clock is stopped stopClock(); startTime = new Date(); showTime(); } //-------------------------------------------------------------------------- function diffSeconds (t1, t2){ // returns the difference between t1 (hh:mm:ss) and t2 (hh:mm:ss)// in seconds! return (t2.getHours()*3600 + t2.getMinutes()*60 + t2.getSeconds()) - (t1.getHours()*3600 + t1.getMinutes()*60 + t1.getSeconds()); } //-------------------------------------------------------------------------- function showTime (){ document.info.time.value = diffSeconds(startTime, new Date()); timerID = setTimeout("showTime()",1000); timerRunning = true; } //-------------------------------------------------------------------------- function initRandom(){ // initialize random number generator var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); constModul = Math.pow(2,48); constFactor = 513.0 constMove = 29741096258473.0; pseudoRandomNumber = (hours+minutes*60+seconds*3600); } //-------------------------------------------------------------------------- function random(){ // returns the next pseudo-random number [0,1] pseudoRandomNumber = (constFactor*pseudoRandomNumber+constMove)%constModul; return (pseudoRandomNumber / constModul); } //-------------------------------------------------------------------------- function getArrayAt(x, y, value){ // Access-method of object-type ObjArray // x,y are zero-based return this[y*this.xSize+x]; } //-------------------------------------------------------------------------- function putArrayAt(x, y, value){ // Access-method of object-type ObjArray // x,y are zero-based this[y*this.xSize+x] = value; } //-------------------------------------------------------------------------- function ObjArray(xSize, ySize){ for (i=0; i<xSize*ySize; i++) this[i] = ""; this.xSize = xSize; this.ySize = ySize; this.getArrayAt = getArrayAt; //Access-methods this.putArrayAt = putArrayAt; } //-------------------------------------------------------------------------- function putAreaAt(x, y, value) // sets the value the displayed "text"-field array of pos (x,y) // x,y are zero-based { var posInArea = (constXSize)+y*(constXSize+2)+(x+1); document.area.elements[posInArea].value = value; } //-------------------------------------------------------------------------- function getAreaAt(x, y) // sets the value the displayed "text"-field array of pos (x,y) // x,y are zero-based { var posInArea = (constXSize)+y*(constXSize+2)+(x+1); return document.area.elements[posInArea].value; } //-------------------------------------------------------------------------- function placeTheBombs(x, y) // places the bombs in the array, except on position x,y { var i, randomXYPos; array.putArrayAt(x, y, BOMB); for (i=0; i<constBombAmnt; i++) { //find a (random) position where there is still no bomb //calculate bombs x,y position randomXYPos = random(); randomXYPos = Math.floor(randomXYPos*constXSize*constYSize); while (array[randomXYPos] == BOMB) { //calculate bombs x,y position randomXYPos = random(); randomXYPos = Math.floor(randomXYPos*constXSize*constYSize); } array[randomXYPos] = BOMB; } array.putArrayAt(x, y, NOBOMB); } //-------------------------------------------------------------------------- function calculateBombsAround() // calculates the amount of bombs that surround each // square and stores it into the array { var x, y, x1, y1, numberOfBombs; for (x=0; x<constXSize; x++) for (y=0; y<constYSize; y++){ if (array.getArrayAt(x, y) == BOMB) continue; numberOfBombs=0; for(x1=x-1; x1<x+2; x1++) for(y1=y-1; y1<y+2; y1++) if((x1>=0) && (y1>=0) && (x1<constXSize) && (y1<constYSize)) if (array.getArrayAt(x1, y1) == BOMB) numberOfBombs++; array.putArrayAt(x, y, " "+numberOfBombs+" "); //putAreaAt(x, y, " "+numberOfBombs+" "); } } //-------------------------------------------------------------------------- function initArea(){ var randomXYPos; var numberOfBombs; var i, x, y; squaresCleared = 0; document.info.bombsLeft.value = constBombAmnt; // init. display for (x=0; x<constXSize; x++) for (y=0; y<constYSize; y++) putAreaAt (x, y, ""); // create area in memory, too array = new ObjArray(constXSize, constYSize); firstTime = true; } //-------------------------------------------------------------------------- function markSquare(x, y){ bottomValue=-1; leftValue=-1; if (getAreaAt(x,y)==MARKED){ putAreaAt(x,y,""); document.info.bombsLeft.value++; } else{ // if the user clicks on a square that has already been opened if (getAreaAt(x,y)!=NOBOMB){ // warn user and abort alert("You've already done this square!") return; } putAreaAt(x,y, MARKED); document.info.bombsLeft.value--; } return; } //-------------------------------------------------------------------------- function openSquare(x, y){ topValue=-1; rightValue=-1; squaresCleared++; // if the user clicks on a square that has already been opened or // been marked if (getAreaAt(x,y)!=NOBOMB){ // warn user and abort alert("You've already done this square!") return; } // prevent user from beeing bombed the first time! if (firstTime) { placeTheBombs(x, y); calculateBombsAround(); firstTime = false; } putAreaAt(x,y, squareContents = array.getArrayAt(x,y)); if (squareContents==BOMB){ alert("GAME-OVER, you lost!"); showAll(); } else{ if (squaresCleared==constXSize*constYSize-constBombAmnt) { alert("Congratulations, you made it in "+ document.info.time.value+" seconds!"); showAll(); }} } //-------------------------------------------------------------------------- function onButtonClicked(button){ var pos = parseInt (button.value); if (button.name=="top") topValue=pos; if (button.name=="bottom") bottomValue=pos; if (button.name=="left") leftValue=pos; if (button.name=="right") rightValue=pos; if ((bottomValue>=0) && (leftValue>=0)) markSquare (bottomValue, leftValue) if ((topValue>=0) && (rightValue>=0)) openSquare(topValue, rightValue) } //-------------------------------------------------------------------------- function showAll() // displays the area like it is represented in the array { var x,y; stopClock(); // init. display for (x=0; x<constXSize; x++) for (y=0; y<constYSize; y++) putAreaAt (x, y, array.getArrayAt(x,y)); } //-------------------------------------------------------------------------- function startNewGame(){ initRandom(); initArea(); startClock(); } // end hiding from old browsers --> </script> </head> <HR> <center> <h1><font color="red">扫 雷</font></h1> <form name=info> <input type="button" value="开始新游戏" onClick="startNewGame()"> 用时:<input type="text" name=time size=7> 剩余雷数:<input type="text" name=bombsLeft size=5></form> <form name=area> <table border=1><tr><td></td><td><input type="button" name=top value=" 0 " onClick="onButtonClicked(this)"></td><td><input type="button" name=top value=" 1 " onClick="onButtonClicked(this)"></td><td><input type="button" name=top value=" 2 " onClick="onButtonClicked(this)"></td><td><input type="button" name=top value=" 3 " onClick="onButtonClicked(this)"></td><td><input type="button" name=top value=" 4 " onClick="onButtonClicked(this)"></td><td></td></tr><tr><td><input type="button" name=left value=" 0 " onClick="onButtonClicked(this)"></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="button" name=right value=" 0 " onClick="onButtonClicked(this)"></td></tr><tr><td><input type="button" name=left value=" 1 " onClick="onButtonClicked(this)"></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td> <input type="text" size=3></td><td><input type="text" size=3></td><td><input type="button" name=right value=" 1 " onClick="onButtonClicked(this)"></td></tr><tr><td><input type="button" name=left value=" 2 " onClick="onButtonClicked(this)"></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="button" name=right value=" 2 " onClick="onButtonClicked(this)"></td></tr><tr><td><input type="button" name=left value=" 3 " onClick="onButtonClicked(this)"></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="button" name=right value=" 3 " onClick="onButtonClicked(this)"></td></tr><tr><td><input type="button" name=left value=" 4 " onClick="onButtonClicked(this)"></td><td><input type="text" size=3></td><td><input type="text" size =3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="text" size=3></td><td><input type="button" name=right value=" 4 " onClick="onButtonClicked(this)"></td></tr><tr><td></td><td><input type="button" name=bottom value=" 0 " onClick="onButtonClicked(this)"></td><td><input type="button" name=bottom value=" 1 " onClick="onButtonClicked(this)"></td><td><input type="button" name=bottom value=" 2 " onClick="onButtonClicked(this)"></td><td><input type="button" name=bottom value=" 3 " onClick="onButtonClicked(this)"></td><td><input type="button" name=bottom value=" 4 " onClick="onButtonClicked(this)"></td><td></td></tr></table> </form> </body></html>
提示:您可以先修改部分代码再运行
站内搜索
:
标题
内容
下一篇
恋爱成***的机率
上一篇
暂无
本栏目最新
栏目最新列表
经典游戏 俄罗斯方块游戏
闯迷宫 经典游戏
射击 游戏
围格子
自信心测试
网站优化策划
栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新
站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息
MIME介绍 及
[
1
] [
2
] [
3
]
巧用Google和迅雷来下载
Transact SQL 常
[
1
] [
2
]
VIA Rhine II Fast Ethe
电脑常用端
[
1
] [
2
] [
3
]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
每日一句:A friend and
每日一句:Theres no tu
经典__悟透JavaScript
伟哥博客
西安房产
123最新电影
三四六四
关于站点
|
免责声明
|
联系站长
|
网站地图
|
陕ICP备07002804号
WEB技术QQ交流群:72840059
©2007 ffasp.com. 版权所有