js鍵盤小遊戲(新手)

來源:互聯網
上載者:User

                              開發步驟:

                               1.   遊戲需求

                               2.  遊戲分析

                               3.  遊戲開發與測試

                               4    遊戲發布

 

                  開發心得:

                                1.寫一行測試一行,避免出錯,不要等到寫了一大堆才測試。

 

                                2.軟體領域中的知識在於積累。

 

                           

 

           以下是代碼:

 

      

<html>  <head>   <title>打字小遊戲</title>   <script>   var ShuZu=new Array("A","B","C","D");       //聲明一個數組裝住字母  var ZiMu='';                                                   //聲明一個全域變數 function start()     {      time=setInterval("move()",300);            //        }    function move()     {      dia.style.top=parseInt(dia.style.top)+20;    // parseint(dia.style.top)>500     {        dia.style.top=50;       }      if(parseInt(dia.style.top)==70)       {        var XiaBiao=Math.floor(Math.random()*4);        ZiMu=ShuZu[XiaBiao];        dia.innerHTML=ZiMu;       }                     dia1.style.top=parseInt(dia1.style.top)+20;      if(parseInt(dia1.style.top)>500)        {        dia1.style.top=50;       }      if(parseInt(dia1.style.top)==70)       {        var XiaBiao1=Math.floor(Math.random()*4);        ZiMu1=ShuZu[XiaBiao1];        dia1.innerHTML=ZiMu1;       }                            dia2.style.top=parseInt(dia2.style.top)+20;      if(parseInt(dia2.style.top)>500)        {        dia2.style.top=50;       }      if(parseInt(dia2.style.top)==70)       {        var XiaBiao2=Math.floor(Math.random()*4);        ZiMu2=ShuZu[XiaBiao2];        dia2.innerHTML=ZiMu2;       }                               }    function stop()     {      clearInterval(time);     }     document.onkeydown=keydown;    function keydown(e)     {      var name=String.fromCharCode(e.which);      //alert(name);      if(ZiMu==name)      {       dia.style.top=50;       }      if(ZiMu1==name)      {       dia1.style.top=50;       }      if(ZiMu2==name)      {       dia2.style.top=50;       }     }        </script>  </head>  <body>   <center>    <button onClick="start()">開始</button>    <button onClick="stop()">結束</button>    <div id="dia" style="position: absolute;width:50px;height:50px;background:red;top:50px; left:0;"></div>             <div id="dia1" style="position: absolute;width:50px;height:50px;background:red;top:50px; left: 200;"></div>             <div id="dia2" style="position: absolute;width:50px;height:50px;background:red;top:50px; left: 500;"></div>   </center>  </body> </html>

 

            

 

 

              

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.