<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>分歧终端机-和谐社会</title> <script language="javascript" type="text/javascript"> var time; var pid,tid; var qvan=["p_w_picpaths/石头.jpg","p_w_picpaths/剪刀.jpg","p_w_picpaths/布.jpg"]; var sum=0; var policesum=0; var terroristsum=0; var peacesum=0; function mystart(){ document.getElementById("resultimg").innerHTML=""; pid=Math.floor(Math.random()*3); tid=Math.floor(Math.random()*3); policeimg.src=qvan[pid]; terroristimg.src=qvan[tid]; document.getElementById("startbtn").disabled=true; document.getElementById("stopbtn").disabled=false; time=setTimeout(mystart,100); } function mystop(){ document.getElementById("startbtn").disabled=false; document.getElementById("stopbtn").disabled=true; clearTimeout(time); sum+=1; document.getElementById("count").innerText=sum; if(pid==0&&tid==1||pid==1&&tid==2||pid==2&&tid==0){ policesum+=1; document.getElementById("policewinimg").height+=10; document.getElementById("policewin").innerText=policesum; document.getElementById("resultimg").innerHTML="<img src='p_w_picpaths/警察.gif' width='100' height='100'>警察获得胜利"; }else if(pid==tid){ peacesum+=1; document.getElementById("peace").innerText=peacesum; document.getElementById("resultimg").innerHTML="<img src='p_w_picpaths/和平.jpg' width='100' height='100'>警察与恐怖分子和平共处"; }else{ terroristsum+=1; document.getElementById("terroristwinimg").height+= 10; document.getElementById("terroristwin").innerText=terroristsum; document.getElementById("resultimg").innerHTML="<img src='p_w_picpaths/恐怖分子.gif' width='100' height='100'>恐怖分子获得了胜利"; } } </script> </head> <body> <center> <h1>让世界和平起来</h1> <p> <b> <font style="color:#000; font-size:4;">第</font> <font style="color:red;font-size:4;" id="count">0</font> <font style="color:#000; font-size:4;">局、</font> <font style="color:#000; font-size:4;">和平:</font> <font style="color:blue;font-size:4;" id="peace">0</font> <font style="color:#000; font-size:4;">次</font> </b> </p><hr/> <p> <img src="p_w_picpaths/成绩.jpg" id="policewinimg" height="1" width="20"> <font style="color:red;font-size:4">警察</font> <font style="color:blue;font-size:4">win:</font> <font style="color:blue;font-size:4" id="policewin">0</font> <font style="color:blue;font-size:4">次</font> </b> <img src="p_w_picpaths/警察.gif" id="policeimg" width="260" height="260"> <img src="p_w_picpaths/pk.jpg" style="width:100px;height:90px"> <img src="p_w_picpaths/恐怖分子.gif" id="terroristimg" width="260" height="260"> <img src="p_w_picpaths/成绩.jpg" id="terroristwinimg" height="1" width="20"> <font style="color:#FF0000;font-size:5">恐怖分子</font> <font style="color:blue;font-size:4">win:</font> <font style="color:blue;font-size:4" id="terroristwin">0</font> <font style="color:blue;font-size:4">次</font> </p> <p> <input type="button" value="开始" id="startbtn" onclick="mystart()" /> <input type="button" value="结束" id="stopbtn" onclick="mystop()" disabled="disabled" /> </p> <h2 id="resultimg"></h2> </center> </body> </html>
javascript基础-猜拳游戏
原创
©著作权归作者所有:来自51CTO博客作者小爱爱0419的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
JavaScript基础
前端基础
Math 数组 字符串 -
谷歌地球引擎中JavaScript语言的基础用法
本文主要对GEE中的JavaScript代码基础规则与语句、函数等加以介绍。本文是谷歌地球引擎(Google Earth Engine,GEE)系列教学文章的第九篇~
GEE 地球引擎 JavaScript 脚本语言 代码规则 -
Javascript高级编程基础之从回调地狱到Async/Await
本文给出Javascript高级编程异步编程有关基础小结,从早期的回调地狱到最新版本的Async/Await。同时,还介绍了另一个开源Bluebird库增强特征及基本使用思路。
回调函数 异步操作 Javascript Promise Async