模拟蔷薇赌博

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>蔷薇赌徒</title>
<meta name="viewport" content="width=device-width" />
<style>
html,
body {
padding: 0;
margin: 0;
}

.fullBox {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: rgb(224, 224, 224);
}

.headline {
background: #3c3c3c;
height: 40px;
width: 100%;
line-height: 40px;
padding: 0 64px 0 24px;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.24);
color: rgba(240, 240, 240, 0.7);
box-sizing: border-box;
font-size: 16px;
line-height: 40px;
font-weight: bold;
}

.bgBox {
overflow: auto;
padding: 12px;
}

.bgBox>div {
float: left;
clear: both;
width: 100%;
padding: 0 12px;
margin: 12px 0;
box-sizing: border-box;
}

.bgBox>div>div {
line-height: 24px;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.24);
padding: 24px;
float: left;
display: flex;
background-color: white;
font-weight: bold;
color: rgba(0, 0, 0, 0.56);
}

.bgBox>div>div>span {
text-align: center;
display: inline-block;
min-width: 54px;
}

.bgBox>div>input {
width: 100%;
height: 100px;
padding: 24px;
padding-bottom: 250px;
box-sizing: border-box;
font-weight: bold;
font-size: 16px !important;
line-height: 26px;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.24);
border: none;
}

.Btns {
width: 100%;
position: absolute;
bottom: 0;
}

.Btns>button {
display: block;
width: 50%;
float: left;
height: 40px;
font-weight: bold;
transition: opacity 0.2s;
border: none;
}

.Btns>button:hover {
opacity: .5;
}

.Btns>button:active {
opacity: .3;
}

.mes {
background-color: white;
position: absolute;
bottom: 76px;
margin: 0 auto;
left: 50%;
transform: translate(-50%, 0);
padding: 24px 24px;
box-shadow: rgba(0, 0, 0, 0.12) 0px 0px 1px, rgba(0, 0, 0, 0.24) 0px 1px 1px;
overflow: hidden;
font-weight: bold;
font-size: 17px;
color: rgba(0, 0, 0, 0.54);
display: none;
}

</style>
</head>
<body>
<div class="fullBox">
<div class="headline">运气【模拟商店运气,回车可快速下注,刷新重置金钱】</div>
<div class="bgBox">
<div>
<div>您有50%的概率会赢</div>
<div>余额 : <span id="yue"></span> 元</div>
<div>余额 : <span id="zeng">--</span>元</div>
</div>
<div>
<input spellcheck="false" autocomplete="off" id="zhu" placeholder="请输入押注的金额 . . ." min="10" maxlength="9"
type="number" />
</div>
</div>
<div class="Btns">
<button id="ces" style="background: white;color:#3C3C3C">概率测试</button>
<button id="ya" style="background: #3c3c3c;color: white;">下注</button>
</div>
<div id="mes" class="mes"></div>
</div>
<script>
var money = 5000;
var yue = document.getElementById("yue");
var zhu = document.getElementById("zhu");
var mes = document.getElementById("mes");
var zeng = document.getElementById("zeng");
var ces = document.getElementById("ces");
yue.innerHTML = money;
zhu.addEventListener("keypress", function(event) {
if (event.keyCode == 13) ya.click();
});
document.getElementById("ya").addEventListener("click", function() {
value = zhu.value;
if (value < 10) {
t = "压注金额必需大于等于10!";
} else {
if (money < value) {
t = "您的余额不足!";
} else {
t = '';
money -= value;
zeng.innerHTML = '<span style="color:red;">-' + value + '</span>';
if (Math.round(Math.random())) {
money += 2 * value;
zeng.innerHTML = '<span style="color:green;">+' + value + '</span>';
}
}
}
yue.innerHTML = money;
if (t) {
mes.innerHTML = t;
mes.style.display = 'block';
setTimeout(function() {
mes.style.display = 'none';
}, 2000);
}
zhu.value = '';
zhu.focus();
});
ces.addEventListener("click", function() {
var sheng = 0;
for (var i = 0; i < 20000; i++) {
sheng += Math.round(Math.random());
}
document.getElementById("ces").innerHTML = '概率测试2w次:' + sheng + '胜';
});
</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/crescawn/p/12590839.html