一步步教你做“锅打灰太狼”

今天给大家分享做一个小游戏“锅打灰太狼”。

首先,我们先来完成一个开始游戏的界面

上代码

//HTML代码
<div class="boss">
			<div class="box1">
				<p>锅打灰太狼</p>
				<button class="btn">开始游戏</button>
				<div class="box_img">
					<img src="img/x5.png" />
					<img src="img/h5.png" />
				</div>
			</div>
<div>

 

//CSS代码
<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			
			a {
				text-decoration: none;
			}
			
			.clearfix::after {
				content: '';
				clear: both;
				display: block;
			}
			
			.clearfix {
				zoom: 1;
			}
			
			.boss {
				width: 320px;
				height: 480px;
				text-align: center;
				margin: 0 auto;
				position: relative;
			}
			
			.box1 {
				width: 100%;
				height: 100%;
				border-radius: 10px;
				background-color: #6495ed;
				overflow: hidden;
			}
			
			.box1 p {
				color: goldenrod;
				font-weight: bolder;
				font-size: 40px;
				margin-top: 100px;
				margin-bottom: 80px;
			}
			
			.box1 button {
				width: 110px;
				height: 50px;
				background: linear-gradient(red, #f2f2f2);
			}
			
			.box_img {
				margin-top: 70px;
			}
			
			.box2 {
				position: relative;
				display: none;
			}
			
			.jdt {
				position: absolute;
				top: 66px;
				left: 63px;
			}
</style>

通过点击开始游戏进入游戏,这里暂时只有进度条和灰太狼出来

先看效果

下面看js部分代码

<script type="text/javascript">
		window.onload = function() {
			var btn = document.querySelector('.btn');
			var box1 = document.querySelector(".box1");
			var box2 = document.querySelector('.box2');
			var img = document.createElement('img');
			var jdt = document.querySelector('.jdt');
			var inxHtl = 0;
			var bar = 180;
			btn.onclick = function() {
				box1.style.display = 'none';
				box2.style.display = 'block';
				//box3.style.display = 'block';
				img.style.position = 'absolute';
				img.style.top = '160px';
				img.style.left = '18px';
				box2.appendChild(img);
				var htl = setInterval(function() {
						
					img.setAttribute('src', 'img/h' + inxHtl + '.png');
						inxHtl++;			
					if(inxHtl >5) {
						clearInterval(htl);
					}
				}, 60)
				var time = setInterval(function() {
					if(bar > 0) {
						bar--;
						jdt.style.width = bar + "px";
					} else {
						clearInterval(time);
					}
				}, 100);
			}
		}
	</script>

 以上就是“锅打灰太狼”小游戏的前面一部分,下期更新打灰太狼

今天的分享就到这,如有错误之处,敬请指正!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值