前端 : 用html ,css,js写一个你画我猜的游戏

1.HTML:

<body>
		<div id = "content">
			<div id = "box1">计时器</div>
			<div id="box">
				<div id= "top">
					<div id = "box-top-left">第几题:</div>
					<div id = "box-top-right">得分:</div>
				</div>
				<div id = "center">
					<div id = "youxi">你画我猜</div>
					<div id="timu">1234</div>
					<div id="btn-start">开始游戏</div>
				</div>
				<div id = "bottom">
					<div id = "right">对</div>
					<div id = "wrong">错</div>
				</div>
			</div>
		</div>
	</body>

2.CSS:
 

<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				width: 100%;
				height: 100%;
			}
			#content{
				width:100%;
				height:100%;
				/* background-color: blue; */
				min-width: 1040px;
				min-height: 800px;
				position: relative;
				
			}
			#box1{
				width: 30%;
				height: 100%;
				position: relative;
				font-size: 50px;
				color: red;
				text-align: center;
				
			}
			#box{
				width:80%;
				height: 100%;
				/* background-color: aqua; */
				position: absolute;
				top: 0;
				right: 0;
			}
			#top{
				width: 80%;
				height: 60px;
				/* background-color: black; */
				position: relative;
				top: 20px;
				right: -150px;
			}
			#box-top-left{
				font-size: 40px;
				font-weight: 600;
				font-family: 楷体;
				margin-left: 50px;
				margin-top: 30px;
				color: gray;
				display: inline-block;
			}
			#box-top-right{
				font-size: 40px;
				font-weight: 600;
				font-family: 楷体;
				display: inline-block;
				margin-left: 600px;
				margin-top: 30px;
				color: gray;
			}
			#center{
				width: 80%;
				height: 400px;
				/* background-color: red; */
				position: relative;
				top: 100px;
				right: -150px;
			}
			#youxi{
				width: 100%;
				height: 100px;
				text-align: center;
				margin: 0 auto;
				font-weight: 700;
				font-family: 宋体;
				font-size: 70px;
				position: absolute;
				top: 100px;
			}
			#btn-start{
				width: 50%;
				height: 40px;
				text-align: center;
				color: crimson;
				margin: 0 auto;
				font-size: 30px;
				position: absolute;
				top: 300px;
				right: 250px;
				background-color: white;
				font-weight: 600;
			}
			#bottom{
				width:80% ;
				height: 100px;
				/* background-color: aqua; */
				position: relative;
				top: 200px;
				right: -150px;
			}
			#right{
				width:30% ;
				height: 40px;
				position: absolute;
				top:10%;
				left: 100px;
				font-size: 50px;
			}
			#wrong{
				position: absolute;
				right:100px;
				top: 10%;
				font-size: 50px;
			}
		</style>

3.JS代码:

<script type="text/javascript">
	var nums =0;
	var scores = 1;
	var yes = document.getElementById("right");
	var no = document.getElementById("wrong");
	var btnstart = document.getElementById("btn-start");
	var bod = document.getElementById("timu");
	var boxl  = document.getElementById("box-top-left");
	var boxr  = document.getElementById("box-top-right");
	var boxt  = document.getElementById("box1");
	
	var str01 = ["伊泽瑞尔","放逐之刃","无双剑姬","暗黑元首","逆羽","幻翎","暗裔剑魔","锤石","泰坦","德玛西亚之力","德玛西亚皇子","青钢影","诺克萨斯之手","艾瑞利亚"];
	
		
		btnstart.onclick=function(){
			nums =0;
			scores = 1;
			suiji();
			var num = 180;
			var id = setInterval(function(){
				num--;
				if(num<0)
				{
					clearInterval(id);
				}
				else{
					boxt.innerHTML = num;
					}
				},1000);
				
			
		}
	function suiji(){
		var num = Math.floor(Math.random()*14);
		bod.innerHTML = str01[num];
		
	}
	yes.onclick = function(){
				suiji();
				nums++;
				scores++;
				boxl.innerHTML = "第" + nums + "题";
				boxr.innerHTML = "得分:"+ scores;
	}
	no.onclick = function(){
				suiji();
				nums++;
				boxl.innerHTML = "第" + nums + "题";
	}
	
</script>

效果展示:

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZHANGα

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值