<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題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關(guān)鍵字專題關(guān)鍵字專題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
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

        使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程)

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 19:37:25
        文檔

        使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程)

        使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程):這篇文章主要介紹了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲,結(jié)合完整實(shí)例形式分析了javascript基于面向?qū)ο髮?shí)現(xiàn)猜拳游戲的具體頁面布局、樣式及功能相關(guān)操作技巧,需要的朋友可以參考下本文實(shí)例講述了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲。分享給大家供大家參
        推薦度:
        導(dǎo)讀使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程):這篇文章主要介紹了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲,結(jié)合完整實(shí)例形式分析了javascript基于面向?qū)ο髮?shí)現(xiàn)猜拳游戲的具體頁面布局、樣式及功能相關(guān)操作技巧,需要的朋友可以參考下本文實(shí)例講述了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲。分享給大家供大家參

        這篇文章主要介紹了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲,結(jié)合完整實(shí)例形式分析了javascript基于面向?qū)ο髮?shí)現(xiàn)猜拳游戲的具體頁面布局、樣式及功能相關(guān)操作技巧,需要的朋友可以參考下

        本文實(shí)例講述了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲。分享給大家供大家參考,具體如下:

        html代碼:

        <!doctype html>
        <html>
         <head>
         <meta charset="UTF-8">
         <title>猜拳游戲</title>
         <link rel="stylesheet" href="css/game.css" rel="external nofollow" ></link>
         </head>
         <body>
         <p id="game">
         <ul class="panel">
         <li>
         <p class="name">我:name</p>
         <p class="anim user"></p>
         </li>
         <li>
         <p class="name">電腦:name</p>
         <p class="anim comp"></p>
         </li>
         </ul>
         <p class="op">
         <button id="play" onclick = "game.Caiquan();">開始</button>
         </p>
         <p id="text" class="text">請開始游戲...</p>
         <ul id="guess" class="guess">
         <li>
         <p class="guess0" onclick="game.verdict(0)">石頭</p>
         </li>
         <li>
         <p class="guess1" onclick="game.verdict(1)">剪刀</p>
         </li>
         <li>
         <p class="guess2" onclick="game.verdict(2)">布</p>
         </li>
         </ul>
         </p>
         <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 p{
         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 p:hover{
         background-color:#ff6699;
         color:#fff;
        }
        p.guess0{
         background-image:url('../img/0.png');
        }
        p.guess1{
         background-image:url('../img/1.png');
        }
        p.guess2{
         background-image:url('../img/2.png');
        }
        #game p.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];
         }
        }
        //父級構(gòu)造函數(shù)用于繼承,共有屬性
        function Caiquan( name ){
         this.name = name;
         this.point = 0;
        }
        //用于繼承下面衍生,共有方法
        Caiquan.prototype.guess = function(){}
        //繼承父,玩家的構(gòu)造函數(shù)
        function User( name ){
         Caiquan.call(this,name);
        }
        User.extend( Caiquan );
        User.prototype.guess = function( point ){
         return this.point = point;
        }
        //電腦的構(gòu)造函數(shù)
        function Comp( name ){
         Caiquan.call(this,name);
        }
        Comp.extend( Caiquan ) ;
        //電腦的猜拳方法,隨機(jī)
        Comp.prototype.guess = function(){
         return this.point = Math.floor( Math.random()*3 );
        }
        //裁判構(gòu)造函數(shù)
        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;
        }
        //提示面板區(qū)域的修改
        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 );

        上面是我整理給大家的,希望今后會(huì)對大家有幫助。

        相關(guān)文章:

        詳細(xì)解讀vue-admin和后端(flask)分離結(jié)合

        使用jquery+css3如何實(shí)現(xiàn)熊貓tv導(dǎo)航

        在jQuery中如何實(shí)現(xiàn)定時(shí)隱藏對話框

        在JS/jQuery中如何實(shí)現(xiàn)DIV延時(shí)幾秒后消失或顯示

        使用原生js實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程)

        使用JavaScript如何實(shí)現(xiàn)猜拳游戲(詳細(xì)教程):這篇文章主要介紹了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲,結(jié)合完整實(shí)例形式分析了javascript基于面向?qū)ο髮?shí)現(xiàn)猜拳游戲的具體頁面布局、樣式及功能相關(guān)操作技巧,需要的朋友可以參考下本文實(shí)例講述了JavaScript基于面向?qū)ο髮?shí)現(xiàn)的猜拳游戲。分享給大家供大家參
        推薦度:
        標(biāo)簽: 游戲 教程 小游戲
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲国产精品yw在线观看| 亚洲视频在线免费观看| 国产精品永久免费10000| 国产成人精品久久免费动漫 | eeuss影院免费直达入口| 久久www免费人成看国产片| 99精品视频免费在线观看| 日韩精品无码区免费专区| 亚洲国产成人久久精品99 | 亚洲av中文无码乱人伦在线r▽| 亚洲国产精品成人综合久久久| 亚洲AV性色在线观看| 免费无码又爽又刺激高潮软件| 日韩免费a级毛片无码a∨| 亚洲毛片基地4455ww| fc2免费人成在线| 亚洲成a人片77777kkkk| 亚洲国产精品成人午夜在线观看| 免费看一区二区三区四区| 久久亚洲AV午夜福利精品一区| 国产亚洲人成在线影院| 国产成人精品免费视频网页大全| 亚洲依依成人精品| 国产乱子伦精品免费无码专区| 亚洲中文久久精品无码| 亚洲国产成人久久精品大牛影视| 免费永久国产在线视频| 中文字幕在线免费看| 中文字幕亚洲不卡在线亚瑟| 亚洲欧洲AV无码专区| 天天影视色香欲综合免费| 亚洲色成人网站WWW永久四虎| 美女被cao免费看在线看网站| 99久久精品国产亚洲| 美女巨胸喷奶水视频www免费| 亚洲AV区无码字幕中文色| 成人午夜视频免费| 亚洲一本到无码av中文字幕 | 亚洲国产精品13p| 最近中文字幕大全中文字幕免费| 国产亚洲精品影视在线产品 |