做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

JavaScript基于面向對象實現的猜拳游戲

來源:懂視網 責編:小采 時間:2020-11-27 22:22:19
文檔

JavaScript基于面向對象實現的猜拳游戲

JavaScript基于面向對象實現的猜拳游戲:本文實例講述了JavaScript基于面向對象實現的猜拳游戲。分享給大家供大家參考,具體如下: html代碼: <!doctype html> <html> <head> <meta charset=UTF-8> <title>猜拳游戲</titl
推薦度:
導讀JavaScript基于面向對象實現的猜拳游戲:本文實例講述了JavaScript基于面向對象實現的猜拳游戲。分享給大家供大家參考,具體如下: html代碼: <!doctype html> <html> <head> <meta charset=UTF-8> <title>猜拳游戲</titl

本文實例講述了JavaScript基于面向對象實現的猜拳游戲。分享給大家供大家參考,具體如下:

html代碼:

<!doctype html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>猜拳游戲</title>
 <link rel="stylesheet" href="css/game.css" rel="external nofollow" ></link>
 </head>
 <body>
 <div id="game">
 <ul class="panel">
 <li>
 <p class="name">我:name</p>
 <div class="anim user"></div>
 </li>
 <li>
 <p class="name">電腦:name</p>
 <div class="anim comp"></div>
 </li>
 </ul>
 <div class="op">
 <button id="play" onclick = "game.Caiquan();">開始</button>
 </div>
 <div id="text" class="text">請開始游戲...</div>
 <ul id="guess" class="guess">
 <li>
 <div class="guess0" onclick="game.verdict(0)">石頭</div>
 </li>
 <li>
 <div class="guess1" onclick="game.verdict(1)">剪刀</div>
 </li>
 <li>
 <div class="guess2" onclick="game.verdict(2)">布</div>
 </li>
 </ul>
 </div>
 <script type="text/javascript" src="js/game.js"></script>
 </body>
</html>

css樣式(字體:迷你簡卡通)

*{
 margin:0px;
 padding:0px;
 font-family:'迷你簡卡通';
 font-size:28px;
}
html,body{
 width:100%;
 height:100%;
 background:rgba(244, 184, 202, 1);
}
ul{
 list-style:none;
}
#game{
 width:800px;
 height:600px;
 margin:auto;
 top:20%;
}
#game ul{
 width:100%;
 height:415px;
}
#game ul li{
 width:50%;
 height:100%;
 float:left;
 text-align:center;
}
#game ul li .anim{
 width:223px;
 height:337px;
 border:10px solid #ff6699;
 border-radius:50%;
 margin:20px auto 0;
 background-position:center;
 background-repeat:no-repeat;
}
.user{
 background:url('../img/readyl.png');
}
.comp{
 background:url('../img/readyr.png');
}
#game .op{
 width:100%;
 text-align:center;
}
#game .op button{
 width:200px;
 height:60px;
 border:10px solid #ff6699;
 background:rgb(253, 217, 227);
 border-radius:50%;
 outline:none;
 cursor:pointer;
 font-weight:bold;
}
#game .op button:hover{
 border-color:#ff0000;
 background-color:#ff0000;
 font-size:36px;
 color:rgb(253, 217, 227);
}
#game .op button.disabled{
 border-color:#bbb;
 color:#bbb;
 background-color:#ccc;
 font-size:28px;
 cursor:default;
}
#game .guess{
 width:220px;
 height:100%;
 position:fixed;
 top:0px;
 left:0px;
 display:none;
}
#game ul.guess li{
 width:100%;
 height:32%;
}
#game ul.guess li div{
 width:100%;
 height:90%;
 border:10px solid #ff6699;
 border-radius:50%;
 background-position:center;
 background-repeat:no-repeat;
 cursor:pointer;
 background-color:rgba(244, 184, 202, 1);
}
#game ul.guess li div:hover{
 background-color:#ff6699;
 color:#fff;
}
div.guess0{
 background-image:url('../img/0.png');
}
div.guess1{
 background-image:url('../img/1.png');
}
div.guess2{
 background-image:url('../img/2.png');
}
#game div.text{
 margin-top:20px;
 text-align:center;
 font-size:50px;
 font-weight:bold;
}

js代碼

Function.prototype.extend = function( fn ){
 for( var attr in fn.prototype ){
 this.prototype[attr] = fn.prototype[attr];
 }
}
//父級構造函數用于繼承,共有屬性
function Caiquan( name ){
 this.name = name;
 this.point = 0;
}
//用于繼承下面衍生,共有方法
Caiquan.prototype.guess = function(){}
//繼承父,玩家的構造函數
function User( name ){
 Caiquan.call(this,name);
}
User.extend( Caiquan );
User.prototype.guess = function( point ){
 return this.point = point;
}
//電腦的構造函數
function Comp( name ){
 Caiquan.call(this,name);
}
Comp.extend( Caiquan ) ;
//電腦的猜拳方法,隨機
Comp.prototype.guess = function(){
 return this.point = Math.floor( Math.random()*3 );
}
//裁判構造函數
function Game( u , c ){
 this.text = document.getElementById('text');
 this.btn = document.getElementById("play");
 this.user = u;
 this.comp = c;
 this.classN =document.getElementsByClassName('name');
 this.guess = document.getElementById("guess");
 this.anim = document.getElementsByClassName("anim");
 this.num = 0;
 this.init();
 this.tiemr = null;
}
Game.prototype.Caiquan = function(){
 this.textValue( '請出拳...' );
 this.BtnDisable();
 this.start();
 this.guess.style.display = 'block';
}
//怎么玩
Game.prototype.start = function(){
 var This = this;
 this.timer = setInterval(function(){
 This.anim[0].className = 'anim user guess' +( ( This.num ++ ) % 3 );
 This.anim[1].className = 'anim comp guess' + ( ( This.num ++ ) % 3 ) ;
 },500)
}
//初始化名字
Game.prototype.init = function(){
 this.classN[0].innerHTML = '我:' + this.user.name;
 this.classN[1].innerHTML = '電腦:' + this.comp.name;
}
//提示面板區域的修改
Game.prototype.textValue = function( val ){
 this.text.innerHTML = val;
}
//按鈕失效
Game.prototype.BtnDisable = function(){
 if( this.btn.disabled ){
 this.btn.disabled = false;
 this.btn.className ='';
 this.btn.innerHTML = '再來一次'
 }else{
 this.btn.disabled = true;
 this.btn.className ='disabled';
 }
}
Game.prototype.verdict = function( point ){
 clearInterval(this.timer);
 var userGu = user.guess(point);
 var compGu = comp.guess();
 this.anim[0].className = 'anim user guess' + userGu;
 this.anim[1].className = 'anim comp guess' + compGu;
 var res = userGu - compGu;
 switch (res){
 case 0:
 this.textValue('平局!!!')
 break;
 case 1:
 case -2:
 this.textValue('lose~~~');
 break;
 case 2:
 case -1:
 this.textValue('win!!!')
 break;
 }
 this.guess.style.display = 'none';
 this.BtnDisable();
}
var user = new User( '銳雯' );
var comp = new Comp( '拉克絲' );
var game = new Game( user , comp );

更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《javascript面向對象入門教程》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結》

希望本文所述對大家JavaScript程序設計有所幫助。

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

JavaScript基于面向對象實現的猜拳游戲

JavaScript基于面向對象實現的猜拳游戲:本文實例講述了JavaScript基于面向對象實現的猜拳游戲。分享給大家供大家參考,具體如下: html代碼: <!doctype html> <html> <head> <meta charset=UTF-8> <title>猜拳游戲</titl
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 汕头市| 军事| 花垣县| 寻乌县| 忻州市| 新巴尔虎右旗| 曲周县| 江川县| 四会市| 石狮市| 靖边县| 乌恰县| 尼勒克县| 廉江市| 东丰县| 衡水市| 罗源县| 临洮县| 武清区| 广南县| 平果县| 安陆市| 杨浦区| 正宁县| 德钦县| 泰宁县| 门源| 道孚县| 永善县| 青神县| 子长县| 马龙县| 平顺县| 怀安县| 胶南市| 贞丰县| 临城县| 都江堰市| 凤山市| 如东县| 德钦县|