`
mushme
  • 浏览: 775647 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

猜数字游戏

 
阅读更多
<html>  
<meta http-equiv="content-type" content="text/html;charset=utf-8">  
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.button, .button:visited {
text-align: center;
font-weight: bold;
color: #fff;
text-shadow:1px 1px 1px #333;
border-radius: 5px;
margin:0 20px 20px 0;
position: relative;
overflow: hidden;

}
.button.red{
font-size:1.5em;
border:1px solid #b42323;
box-shadow: 0 1px 2px #e99494 inset,0 -1px 0 #954b4b inset,0 -2px 3px #e99494 inset;
background: -webkit-linear-gradient(top,#d53939,#b92929);
background: -moz-linear-gradient(top,#d53939,#b92929);
background: linear-gradient(top,#d53939,#b92929);
}
.button.yellow{
border:1px solid #d2a000;
box-shadow: 0 1px 2px #fedd71 inset,0 -1px 0 #a38b39 inset,0 -2px 3px #fedd71 inset;
background: -webkit-linear-gradient(top,#fece34,#d8a605);
background: -moz-linear-gradient(top,#fece34,#d8a605);
background: linear-gradient(top,#fece34,#d8a605);
}
</style>
<input type="text" name="guessno" id="guessno" style="line-height:3em" /> 
<input type="button" value="guess" onclick="startGuess()" class="button red" /> &nbsp;
<input type="button" value="replay" onclick="reset()" class="button yellow"/>  
<div style="height:50px;width:90%;font-size:1.7em" id="content">  
</div>

<script>
//利用二分法,七次可以猜解出100之内的数字
var magicno;
var guesscount;
var content;
function reset(){
magicno=parseInt(Math.random()*100+1);
guesscount=10;
document.getElementById("content").innerHTML="<span style='color:red'>0到100之间,10次机会.<span>";
}
function startGuess(){
var guessno=document.getElementById("guessno").value; 
document.getElementById("guessno").value=""; 
content=document.getElementById("content"); 
if(guesscount<=0){
alert("You Lost.");
return false;
}
if(guessno && guessno>0 && guessno <100){
guesscount--;
if(guessno==magicno){
if(guesscount>7){
alert("YOU WIN!!!\r\n你太厉害了,你已经获得蒙之神称号。");
return false;
}
if(guesscount>2){
alert("YOU WIN!!!\r\n你太棒了了,你的智慧已经达到了人类极限。");
return false;
}
if(guesscount>=0){
alert("YOU WIN!!!但是我相信你可以做的更好");
return false;
}
alert("YOU WIN!!!");
}else if(guessno>magicno){
content.innerHTML=guessno+" 太大了.还有[<span style='color:blue'>"+guesscount+"</span>]次机会.<br />"+content.innerHTML;

}else if(guessno<magicno){
content.innerHTML=guessno+" 太小了.还有[<span style='color:blue'>"+guesscount+"</span>]次机会.<br />"+content.innerHTML;
}else{
alert("这是几个意思");
}

}else{
alert("输入错误");
//输入的数值必须在0到100之间。
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics