這篇文章將為大家詳細(xì)講解有關(guān)使用vue實現(xiàn)一個簡易打地鼠小游戲,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>打地鼠簡易版</title>
<script src="js/vue.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
#main{border: 1px solid #000;}
.ds{ float: left;border: 1px solid #000;box-sizing: border-box;}
.dd{background-color: #3E8F3E;}
</style>
</head>
<body>
<div id="app">
<div>倒計時{{t}}</div>
<div>分?jǐn)?shù){{fs}}</div>
<div v-if="t<=0">游戲結(jié)束</div>
<div id="main" v-bind:>
<div class="ds" v-bind:class="{dd:v==s}" v-on:click="da(v)" v-for="v in x*y" v-bind:></div>
</div>
</div>
<script type="text/javascript">
var vm=new Vue({
el:'#app',
data:{
x:5,//地鼠格列數(shù)
y:5,//地鼠格行數(shù)
w:100,//地鼠格寬度
h:100,//地鼠格高度
t:10,//時間
dsq:null,
dsq2:null,
s:0,//地鼠位置
fs:0,
ys:true,//用于解決游戲結(jié)束點擊繼續(xù)得分問題
ty:false//用于解決連擊得分問題
},
methods:{
da(i){
if(this.s==i && this.ys && this.ty){
this.ty=false;
this.fs++;
}
}
},
created(){
this.dsq=setInterval(()=>{
this.t--;
if(this.t<=0){
clearInterval(this.dsq);
clearInterval(this.dsq2);
this.ys=false;
}
},1000);
this.dsq2=setInterval(()=>{
this.ty=true
this.s=parseInt(Math.random()*this.x*this.y);
},2000);
}
})
</script>
</body>
</html>
當(dāng)前文章:使用vue實現(xiàn)一個簡易打地鼠小游戲-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://www.yijiale78.com/article16/phcdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、ChatGPT、自適應(yīng)網(wǎng)站、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容