- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) >
- 微信小程序如何實(shí)現扎金花
這篇文章主要介紹微信小程序如何實(shí)現扎金花,文中介紹的非常詳細,具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
微信小程序 扎金花
實(shí)現效果圖:
app.json:
{ "pages":[ "pages/index/index" ], "window":{ "navigationBarBackgroundColor": "#333333", "navigationBarTextStyle":"white", "navigationBarTitleText": "炸金花", "backgroundColor":"#ffffff", "backgroundTextStyle":"light", "enablePullDownRefresh":false } }
index.js:
Page({ data:{ num1:1, num2:2, num3:3, imgNum1:1, imgNum2:2, imgNum3:3, b1:"white", b2:"white", b3:"white", flag:true, butype:"primary", butext:"開(kāi)始", hidden:true, score:0 }, start:function(){ var that=this; that.setData({ butype:"default", butext:"停止" }) if(this.data.flag){ this.go=setInterval(function(){ that.setData({ num1:Math.ceil(Math.random()*10), num2:Math.ceil(Math.random()*10), num3:Math.ceil(Math.random()*10), imgNum1:Math.ceil(Math.random()*4), imgNum2:Math.ceil(Math.random()*4), imgNum3:Math.ceil(Math.random()*4), b1:"#"+Math.floor(Math.random()*1000000), b2:"#"+Math.floor(Math.random()*1000000), b3:"#"+Math.floor(Math.random()*1000000) }) },100) this.setData({ flag:false, hidden:true, score:0 }) }else{ clearInterval(this.go) this.setData({ flag:true, butype:"primary", butext:"開(kāi)始", b1:"white", b2:"white", b3:"white" }) var n1=this.data.num1; var n2=this.data.num2; var n3=this.data.num3; var img1=this.data.imgNum1; var img2=this.data.imgNum2; var img3=this.data.imgNum3; var result=n1+n2+n3; if(img1==img2&&img2==img3){ result+=20; }else if(img1==img2 || img2==img3 || img1==img3){ result+=10; } var newarr=new Array(); newarr.push(n1) newarr.push(n2) newarr.push(n3) for(var i=0;i<newarr.length;i++){ for(var j = i + 1;j<newarr.length;j++){ if(newarr[i]>newarr[j]){ var tmp = newarr[i]; newarr[i] = newarr[j]; newarr[j] = tmp; } } } if(((newarr[2]-newarr[1])==1)&&((newarr[1]-newarr[0])==1)){ result+=30; }else if(newarr[2]==newarr[1] || newarr[2]==newarr[0] || newarr[0]==newarr[1]){ result+=10; }else if(newarr[2]==newarr[1]&&newarr[2]==newarr[0]){ result+=40; } this.setData({ hidden:false, score:result }) } }, onShareAppMessage: function () { return { title: "大小之爭", desc: '激烈的競技游戲', path: '/pages/index/index' } } })
index.wxml:
<view hidden="{{hidden}}">恭喜你得了{{score}}分!</view> <view > <view class="container" > <text class="text">{{num1}}</text> <image class="img" src="../../images/{{imgNum1}}.png" ></image> <text class="text1">{{num1}}</text> </view> <view class="container" > <text class="text">{{num2}}</text> <image class="img" src="../../images/{{imgNum2}}.png" ></image> <text class="text1">{{num2}}</text> </view> <view class="container" > <text class="text">{{num3}}</text> <image class="img" src="../../images/{{imgNum3}}.png" ></image> <text class="text1">{{num3}}</text> </view> </view> <button bindtap="start" type="{{butype}}" >{{butext}}</button> <view > <view>1.如果三張數字相同得40分,如果三張數字是連續的得30分,如果兩個(gè)數字是相同的得10分</view> <view>2.如果三張花色一樣得20分,如果兩張花色一樣得10分</view> <view>3.三張數字之和</view> <view>以上所有數字的總和為總分</view> </view>
index.wxss:
.container{width:30%;height:200px;position:relative;border:1px solid #787775;box-sizing:border-box; display: inline-block;flex:1;margin:10px;border-radius:10px;box-shadow: 5px 5px 3px #787775} .text{width:30px;height:30px;position:absolute;top:15px;left:15px;font-size: 25px;font-weight: bolder} .img{width:50px;height:50px;position:absolute;top:50%;left:50%;margin-left:-25px;margin-top:-25px} .text1{width:30px;height:30px;position:absolute;bottom:15px;right:15px;font-size: 25px;font-weight: bolder;transform: rotate(180deg)}
1.png:
2.png:
3.png
4.png
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系站長(cháng)郵箱:ts@56dr.com進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2 建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站