使用JS语言来开发 石头剪刀布游戏

sharembweb 30次浏览
视频观看地址:


源码下载地址:
github下载

代码部分:


<style>/*使用JS语言来开发 石头剪刀布游戏*/#computer{float:left;}
#vs{float:left;width:140px; font-weight:bold;text-align:center;}
#self{float:left;}
#action a{line-height:30px;padding:8px;}</style><div id="computer">电脑<br>86币</div>
<div id="vs">剪刀 VS 石头<br><font color=green>你赢了</font></div>
<div id="self">玩家<br>90币</div>
<div style="clear:both"></div>
<div id="action"><a href="javascript:handleResult('石头')">石头</a><a href="javascript:handleResult('剪刀')">剪刀</a><a href="javascript:handleResult('布')">布</a><a href="javascript:handleResult('')">重置</a></div><div id="record"></div>
<script>var nSelf=88,nComputer=88,msg="",recordList="",sResult="";handleResult();
function handleResult(selfAction){ 
	if(selfAction!="" && selfAction!=undefined){
		var computerAction="布"
		var n=Math.round(Math.random()* 2)+1
		if(n==1){
			computerAction="石头"
		}else if(n==2){
			computerAction="剪刀"
		}
		if( (selfAction=="石头"&&computerAction=="剪刀")||(selfAction=="剪刀"&&computerAction=="布")||(selfAction=="布"&&computerAction=="石头")){
			nSelf++;nComputer--
			sResult="<font color=green>你赢了</font>"
		}else if( (selfAction=="石头"&&computerAction=="布")||(selfAction=="剪刀"&&computerAction=="石头")||(selfAction=="布"&&computerAction=="剪刀")){
			nSelf--;nComputer++
			sResult="<font color=red>你输了</font>"
		}else{
			sResult="<font color=gray>平局</font>"
		}
		
		msg=computerAction + " VS " + selfAction + "<br>"+sResult
		recordList+=computerAction + " VS " + selfAction + "=" +sResult + "("+ nSelf+")<br>"
	}else{ 
		msg="VS"
		nSelf=88;nComputer=88;recordList="" 
	}
	document.getElementById("computer").innerHTML="电脑<br>"+nComputer+"币"
	document.getElementById("self").innerHTML="玩家<br>"+nSelf+"币"
	document.getElementById("vs").innerHTML=msg 
	document.getElementById("record").innerHTML=recordList}</script>


万水千山总是情,微信关注行不行
PAAJCMS二维码
随机内容

表情

共2条评论
  • 网友评论:

    赞一个

    2020-07-24 16:26:24 回复

  • 网友评论:

    学习了

    2020-07-24 16:26:24 回复

友情链接