?? 前天晚上,没有什么事可做,用js重新写好了我之前用c#些的一个小游戏!
?
? 下面是源代码:
<html> <head> <title>My Game 【家庭骰子】 【作者:艾彦波】</title> <style type="text/css"> #authorInfo p{ margin-top:2px; color:bule; font-size:14 } .mes p{ margin-top:10px; color:red; font-size:12 } </style> </head> <body bgcolor="pink"> <h3 style="color:red" align="center">网页版【家庭骰子】出来了!</h3> <div style="margin-top:40px"> <table align="center"> <tr align="center"> <td rowspan="4"> <select name="list" id="list" multiple size="10" style="width:150px"></select> </td> <td> <input type="button" value="开始" onclick="gameRun()"> </td> </tr> <tr align="center"> <td> <input type="button" value="停止" onclick="stopGame()"> </td> </tr> <tr> <td> 恭喜!您的任务是: </td> </tr> <tr align="center"> <td> <span style="color:blue" name="showJob" id="showJob">游戏未开始</span> </td> </tr> <tr> <td colspan="2"> <input style="border:0px;background-color:pink" type="button" value="复位" onclick="init()"> <input style="border:0px;background-color:pink" type="button" value="读取xml" onclick="readXml()"> </td> </tr> </table> </div> <div id="authorInfo" style="margin-top:140px"> <p align="center">作者:艾彦波 <p align="center">javaeye博客:<a href=" http://aiyanbo.iteye.com" target="_blank">http://aiyanbo.iteye.com</a> <p align="center">E-mail:<a href="mailto:ayanbo@yeah.net">ayanbo@yeah.net</a> <p align="center">QQ:448267886 </div> <div class="mes" style="margin-top:50px"> <p align="center">注意:本游戏仅供娱乐,请勿用于正常生活秩序中! <p align="center">您好!MyGame将游戏的配置文件放在c:/Proparm Files/mygame 中如果您不再使用该游戏您可以删除此文件!(现在没有开放此功能,所以没有上述文件夹) <p align="center">CopyRight@aiyanbo 2010 </div> </body> <script language="javascript"> var arr=["洗衣服","洗碗","买菜","扫地","做饭","休息"]; var list=document.getElementById("list"); var timeout; var m; var cli=0; onload=function(){ window.open("http://aiyanbo.iteye.com"); window.open("http://user.qzone.qq.com/448267886"); init(); } function init(){ clearTimeout(timeout); list.length=0; document.getElementById("showJob").innerHTML="游戏未开始"; for(var i=0;i<arr.length;i++){ var o=new Option(arr[i],arr[i]); list.options.add(o); } cli=0; } function gameRun(){ if(cli==1) return; cli=1; startGame(); } function startGame(){ if(list.length==0){ alert("您的任务已经用完了,请点击【确定】重新开始!"); clearTimeout(timeout); init(); return; } m=parseInt((Math.random()*10000)%list.length); list.selectedIndex=m; document.getElementById("showJob").innerHTML=list[m].value; timeout=setTimeout("startGame()",1); } function stopGame(){ if(cli==0) return; if(!timeout) return; clearTimeout(timeout); list.remove(m); timeout=null; cli=0; } function readXml(){ var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; var bool=xmlDoc.load("mygame.xml"); alert(bool); } </script> </html>
?
?
?
?
有些写得不好的地方,还望朋友帮我指正下!