自制狂拍灰太狼小游戏(HTML+CSS+JavaScript)
今天想想,很久没有打开博客了,所以在这里给大家上点我暑假的存“粮”。这里推荐大家一个前端开发神器App: HBuilder
后续还会有多个同款系列:如自制微博、自制QQ音乐、自制品优购网站等等。
如果有需要学习系列的我有时间的时候也会分享出来,如
尚有挺多的,这里就不一一举例子了。
从这里正文就开始了,先来看看代码目次,让大家有信心自己也能做出来:
实在就三个代码需要自己写:1.css 、 1.js 和 狂拍灰太狼.html
看到这里,是不是觉得很简单呀!相信你们都可以。
在这里说明一下,由于我是抠图做出来的,所以难免不那么美观,所以大家就将就一下吧!
再来看看游戏中的效果图:
最后也大家最想要的源代码,立刻给大家附上:
狂拍灰太狼.html
0
开始游戏
游戏规则
游戏规则:
1.游戏时间:60s
2.拼手速,殴打灰太狼+10分
3.殴打小灰灰-10分
[关闭]
GAME OVER
重新开始
1.css
*{
margin: 0;
padding: 0;
}
.container{
width: 320px;
height: 480px;
background: url("../img/game_bg.png") no-repeat 0 0;
margin: 50px auto;
position: relative;
}
.container>h1{
color: white;
margin-left: 60px;
}
.container>.progress{
width: 119px;
height: 16px;
background: url("../img/progress.png") no-repeat 0 0;
position: absolute;
top: 58px;
left: 60px;
}
.container>.start{
width: 150px;
line-height: 35px;
text-align: center;
color: white;
background: linear-gradient(#E55C3D,#C50000);
border-radius: 20px;
border: none;
font-size: 20px;
position: absolute;
top: 320px;
left: 50%;
margin-left: -75px;
}
.container>.rules{
width: 90%;
height: 20px;
background: #ccc;
position: absolute;
bottom: 30px;
left: 0;
text-align: center;
}
.container>.rule{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
position: absolute;
left: 0;
top: 0;
padding-top: 100px;
box-sizing: border-box;
text-align: center;
display: none;
}
.rule>p{
line-height: 50px;
color: white;
}
.rule>a{
color: red;
}
.container>.mask{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
position: absolute;
left: 0;
top: 0;
padding-top: 200px;
box-sizing: border-box;
text-align: center;
display: none;
}
.mask>h1{
color: #ff4500;
text-shadow: 3px 3px 0 #fff;
font-size: 40px;
}
.mask>button{
width: 150px;
line-height: 35px;
text-align: center;
color: white;
background: linear-gradient(#74ACCF,#007DDC);
border-radius: 20px;
border: none;
font-size: 20px;
position: absolute;
top: 320px;
left: 50%;
margin-left: -75px;
}
1.js
$(function(){
//游戏规则点击
$(".rules").click(function(){
$(".rule").stop().fadeIn(100);
});
//关闭按钮点击
$(".close").click(function(){
$(".rule").stop().fadeOut(100);
});
//开始游戏点击
$(".start").click(function(){
$(this).stop().fadeOut(100);
//处理进度条
progressHandler();
wolfAnimation1();
});
//重新开始点击
$(".reStart").click(function(){
$(".mask").stop().fadeOut(100);
//处理进度条
progressHandler();
wolfAnimation1();
});
function progressHandler(){
$(".progress").css({
width: 119
});
var timer = setInterval(function(){
var progressWidth = $(".progress").width();
progressWidth -= 1;
$(".progress").css({
width: progressWidth
});
if(progressWidthwolfIndexEnd){
wolfImage.remove();
clearInterval(wolfTimer);
wolfAnimation1();
}
//图片内容
wolfImage.attr("src" , wolfType);
wolfIndex++;
},300);
//添加图片到界面
$(".container").append(wolfImage);
gameRules(wolfImage);
}
function wolfAnimation2(){
$(".wolfImage").remove();
clearInterval(wolfTimer);
}
function gameRules(wolfImage){
wolfImage.one("click",function(){
window.wolfIndex = 5;
window.wolfIndexEnd = 9;
var src = $(this).attr("src");
var flag = src.indexOf("h") >= 0;
// alert(flag);
if(flag){
$(".score").text(parseInt($(".score").text()) + 10);
}else{
$(".score").text(parseInt($(".score").text()) - 10);
}
});
}
});
自制小游戏到这里就结束了,下次再见啦!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]