基于Vue实现原神抽卡简易代码算法(纯金光率)

狠人话不多,直接上代码就完事了,代码中有详细说明…


<template>
	<div id="container">
		<button @click="clickGoodLuck(1)">祈愿1</button>
		<button @click="clickGoodLuck(10)">祈愿10</button>
	</div>
</template>
<script>
	export default {
		name: "elect",
		data() {
			return {
				// 抽卡概率属性
				probability_golden: 0.6,	//金卡基础概率
                probability_violet: 5.1,	//紫卡基础概率
				totoalCount: 0,				//总抽卡次数
				accNoGoldenCount: 0, 		//不出金次数
				accNoVioletCount: 0, 		//不出紫次数
				awardColor: "blue",			//出啥颜色卡
			};
		},
		methods: {
			// 点击抽卡 1次 or 10次
			clickGoodLuck(times) {
                if (times == 1) {
					this.computeProOne();
                } else {
					this.computeProTen();
				}
            },
			// 抽中金卡,重新初始化
			initAwardedGolden(){
				this.probability_golden = 0.6;
				this.accNoGoldenCount = 0;
				this.awardColor = "golden";
			},
			// 抽中紫卡,重新初始化
			initAwardedViolet(){
				this.probability_violet = 5.1;
				this.accNoVioletCount = 0;
				this.awardColor = "violet";
			},
			//单抽概率计算
			computeProOne(){
				this.totoalCount++;
                let randomGolden = (Math.random() * 100).toFixed(2);
                let randomNumViolet = (Math.random() * 100).toFixed(2);
				//是否出金 出金大保低
				if(this.accNoGoldenCount>=90){
					console.log("出金啦/大保低:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
					this.initAwardedGolden();
					return;
				}
				//是否出金 出金小保低
				if(this.accNoGoldenCount>=73){
					if (this.probability_golden >= randomGolden) {
						console.log("出金啦/小保低:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
						this.initAwardedGolden();
						return;
					}else{
						this.probability_golden += 6;
					}
				}
				//是否出金  出金小欧皇
				if(this.accNoGoldenCount<=73){
					if (this.probability_golden >= randomGolden) {
						console.log("出金啦/欧皇:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
						this.initAwardedGolden();
						return;
					}
				}
				//是否出紫 
				if(this.probability_violet >= randomNumViolet){
					console.log("出紫/欧皇:", this.probability_violet, "~" + randomNumViolet+" 抽卡次数:",this.totoalCount);
					this.initAwardedViolet();
				}else{
					this.accNoVioletCount++;
					if(this.accNoVioletCount==8){
						this.probability_violet += 51;
					}
					if(this.accNoVioletCount==9){
						this.probability_violet = 100;
					}
					// 出蓝
					this.awardColor = "blue";
					console.log("出蓝:", this.probability_violet, "~" + randomNumViolet+" 抽卡次数:",this.totoalCount);
				}
				this.accNoGoldenCount++;
			},
			//10连概率计算
			computeProTen(){
				for (let i = 0; i < 10; i++) {
					this.computeProOne();
				}
			},
		},
	};
</script>

在console控制台查看抽卡信息:
在这里插入图片描述

古有云:绝云天府有仙徒,其名申鹤习神术。

壁纸放送:
在这里插入图片描述

好的,使用Vue模拟原神抽卡,可以按照以下步骤进行: 1. 创建一个Vue实例,并在其中定义卡池和抽卡结果的数据。 ```javascript new Vue({ el: '#app', data: { pool: [ { name: '角色1', type: 'character', rate: 0.006 }, { name: '角色2', type: 'character', rate: 0.006 }, { name: '角色3', type: 'character', rate: 0.006 }, { name: '武器1', type: 'weapon', rate: 0.07 }, { name: '武器2', type: 'weapon', rate: 0.07 }, { name: '武器3', type: 'weapon', rate: 0.07 }, { name: '普通物品1', type: 'item', rate: 0.77 }, { name: '普通物品2', type: 'item', rate: 0.77 }, { name: '普通物品3', type: 'item', rate: 0.77 }, ], result: [], pityCount: 0, history: [], }, methods: { // 抽卡方法 draw() { let random = Math.random(); let index = 0; while (random > 0) { random -= this.pool[index].rate; index++; } index--; let card = this.pool[index]; if (card.type === 'character' || card.type === 'weapon') { this.pityCount = 0; } else { this.pityCount++; } this.result.push(card.name); this.history.push(card.name); if (this.pityCount >= 10) { this.result.push('保底物品'); this.history.push('保底物品'); this.pityCount = 0; } }, // 重置方法 reset() { this.result = []; this.pityCount = 0; }, }, }); ``` 2. 在页面上渲染卡池和抽卡结果,并绑定抽卡和重置事件。 ```html <div id="app"> <h2>卡池</h2> <ul> <li v-for="card in pool"> {{ card.name }}({{ card.type }},{{ card.rate * 100 }}%) </li> </ul> <button @click="draw">抽卡</button> <button @click="reset">重置</button> <h2>抽卡结果</h2> <ul> <li v-for="card in result"> {{ card }} </li> </ul> <h2>历史记录</h2> <ul> <li v-for="card in history"> {{ card }} </li> </ul> </div> ``` 3. 在抽卡方法中实现抽卡逻辑,并将抽卡结果和历史记录添加到页面上。 以上是一个简单的原神抽卡模拟实现,你可以根据实际需求对其进行优化和扩展。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值