使用chrome插件来开发 石头剪刀布游戏

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


源码下载地址:
github下载

代码部分:


manifest.json
{
	"manifest_version": 2,
	"name": "石头剪刀布游戏",
	"description": "使用chrome插件来开发 石头剪刀布游戏 由喜欢TA QQ313801120原创制作",
	"version": "1.0",
	"browser_action": {
		"default_title": "石头剪刀布游戏",
		"default_icon": "XiYueTa313801120.png",
		"default_popup": "xiyueta313801120.html"
	},
	"content_scripts": [{
		"matches": [
			"<all_urls>"
		],
		"js": ["content.js"]
	}]
}


background.js
console.log("石头剪刀布游戏 background run");


content.js
//使用chrome插件来开发 石头剪刀布游戏
console.log("石头剪刀布游戏");


xiyueta313801120.html
<style>/*使用chrome插件来开发 石头剪刀布游戏*/
#box{width:240px; height: 300px;}
#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="box">
<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="#">石头</a><a href="#">剪刀</a><a href="#">布</a><a href="#">重置</a></div><div id="record"></div>
<script src="xiyueta313801120.js"></script>
</div>


xiyueta313801120.js
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
}

var a = document.getElementsByTagName("a")
for (var i = 0; i <= a.length; i++) {
	var oBtn = a[i]
	oBtn.onclick = function(e) {
		var s = this.innerHTML
		if (s == "重置") s = ""
		handleResult(s)
	};
}


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

表情

共2条评论
  • 网友评论:

    赞一个

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

  • 网友评论:

    学习了

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

友情链接