欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js仿3366小游戲選字游戲

 更新時(shí)間:2016年04月14日 14:53:44   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了js仿3366小游戲選字游戲

本文實(shí)例為大家分享了js仿3366小游戲中“你是色盲嗎”游戲,大家先來(lái)挑戰(zhàn)一下

游戲目標(biāo): 按畫(huà)面中出現(xiàn)的文字的顏色來(lái)選擇顏色,千萬(wàn)不要被顏色的困局打擾,眼睛一定要放亮哦,游戲開(kāi)始時(shí)會(huì)有10分,每答對(duì)一題得一分,總共有10分,時(shí)間用完游戲會(huì)結(jié)束。
操作說(shuō)明: 鼠標(biāo)點(diǎn)擊選擇顏色

1、效果圖:

原圖:

模仿:

代碼:

<!DOCTYPE html>
<html>
 
  <head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
      .wrap {
        width: 400px;
        height: 600px;
        border: 1px solid black;
        margin: 0 auto;
      }
       
      .head {
        width: 100%;
        height: 50px;
        overflow: hidden;
      }
       
      .time {
        float: left;
        width: 150px;
        height: 100%;
        line-height: 50px;
        font-size: 20px;
        text-align: center;
      }
       
      .score {
        width: 150px;
        height: 100%;
        float: right;
        line-height: 50px;
        font-size: 20px;
        /*text-align: center;*/
      }
       
      .middle {
        width: 100%;
        height: 450px;
      }
       
      .text {
        width: 100%;
        height: 300px;
        font-size: 200px;
        text-align: center;
        line-height: 300px;
      }
       
      .alert {
        width: 80%;
        height: 150px;
        margin: 0 auto;
        text-indent: 2em;
        font-size: 25px;
      }
       
      .bottom {
        width: 100%;
        height: 100px;
        overflow: hidden;
      }
       
      .bottomText {
        width: 20%;
        height: 100px;
        float: left;
        text-align: center;
        line-height: 100px;
        font-size: 70px;
        cursor: pointer;
      }
    </style>
  </head>
 
  <body>
    <div class="wrap">
      <div class="head">
        <div class="time">時(shí)間:10s</div>
        <div class="score">分?jǐn)?shù) :0</div>
      </div>
      <div class="middle">
        <div class="text">藍(lán)</div>
        <div class="alert">根據(jù)上面的字的顏色從下面選擇正確的字,選擇正確自動(dòng)開(kāi)始</div>
      </div>
      <div class="bottom">
        <div class="bottomText">紅</div>
        <div class="bottomText">綠</div>
        <div class="bottomText">黑</div>
        <div class="bottomText">藍(lán)</div>
        <div class="bottomText">黃</div>
      </div>
    </div>
  </body>
  <script type="text/javascript">
    //變化的核心 獲得不重復(fù)的亂序數(shù)組(數(shù)組中下標(biāo)值)
     
    function random(min, max) {
      return parseInt(Math.random() * (max - min + 1)) + min;
    }
    //不重復(fù)的數(shù)組
    function randomArr() {
      var arr = [];
      while (arr.length < 5) {
        var temp = random(0, 4);
        if (arr.indexOf(temp) == -1) {
          arr.push(temp);
        }
      }
      return arr;
    }
    function fresh() {
      //中間字 變化
      var textIndex = random(0, 4);
       colorIndex = random(0, 4);
      textDiv.innerHTML = textArr[textIndex];
      textDiv.style.color = colorArr[colorIndex];
      //獲取亂序下標(biāo)數(shù)組
      var textRandoms = randomArr();
      var colorRandoms = randomArr();
      for (var i = 0; i < bottomDivs.length; i++) {
        //通過(guò)亂序下標(biāo)獲取文本,賦值給div
        bottomDivs[i].innerHTML = textArr[textRandoms[i]];
        bottomDivs[i].style.color = colorArr[colorRandoms[i]];
        //保存亂序下標(biāo)
        bottomDivs[i].index = textRandoms[i];
      }
    }
    var textDiv = document.querySelector(".text");
    var bottomDivs = document.querySelectorAll(".bottomText");
    var timeDiv = document.querySelector(".time");
    var scoreDiv = document.querySelector(".score");
    var alertDiv = document.querySelector(".alert");
    var textArr = ["紅", "綠", "藍(lán)", "黃", "黑"];
    var colorArr = ["red", "green", "blue", "yellow", "black"];
     var colorIndex=0;
     var timer = null;
     var isplaying = false;
     var countDown = 10;
     var score = 0;
     fresh();
    for (var i = 0; i < bottomDivs.length; i++) {
      bottomDivs[i].onclick = function(){
        //判斷
        if(colorIndex == this.index &&countDown!=0 ){
          //刷新
          score ++;
          isplaying =true;
          //分?jǐn)?shù)增加
          fresh();
          scoreDiv.innerHTML = "分?jǐn)?shù): "+score ;
          alertDiv.style.opacity = 0;
        }else if(colorIndex != this.index &&isplaying){
          //點(diǎn)錯(cuò)時(shí)間減小
          countDown --;
          //更新時(shí)間變化
          timeDiv.innerHTML = "時(shí)間: " + countDown +"s";
          //判斷清理定時(shí)器
          if(countDown <= 0){
            clearInterval(timer);
            isplaying = false;
          }
        }
      }
    }
    //定時(shí)器,監(jiān)聽(tīng)游戲進(jìn)行
    timer = setInterval(function(){
      if(isplaying){
        countDown --;
        timeDiv.innerHTML = "時(shí)間: " + countDown +"s";
        if(countDown <= 0){
          clearInterval(timer);
          isplaying =false;
          alert("game over!!");
        }
        //停止游戲
      }else{
         
      }
    },1000);
  </script>
 
</html>

以上就是本文的全部?jī)?nèi)容,希望大家能夠挑戰(zhàn)成功。

相關(guān)文章

  • js倒計(jì)時(shí)搶購(gòu)實(shí)例

    js倒計(jì)時(shí)搶購(gòu)實(shí)例

    這篇文章主要介紹了js倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)方法,方便一些提示重要日期的來(lái)臨,本實(shí)例特別適合用于商品倒計(jì)時(shí)搶購(gòu)活動(dòng),感興趣的小伙伴們可以參考一下
    2015-12-12
  • IE的有條件注釋判定IE版本詳解(附實(shí)例代碼)

    IE的有條件注釋判定IE版本詳解(附實(shí)例代碼)

    IE的有條件注釋是一種專有的(因此是非標(biāo)準(zhǔn)的)、對(duì)常規(guī)(X)HTML注釋的Miscrosoft擴(kuò)展。顧名思義,有條件注釋使你能夠根據(jù)條件(比如瀏覽器版本)顯示代碼塊(不一定就是css,也可以是html代碼,甚至是JavaScript代碼)。
    2012-01-01
  • layui使用templet格式化表格數(shù)據(jù)的方法

    layui使用templet格式化表格數(shù)據(jù)的方法

    今天小編就為大家分享一篇layui使用templet格式化表格數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-09-09
  • JS中的二叉樹(shù)遍歷詳解

    JS中的二叉樹(shù)遍歷詳解

    這篇文章主要為大家詳細(xì)介紹了JS中的二叉樹(shù)遍歷,何為二叉樹(shù),什么是二叉樹(shù)的遍歷,感興趣的小伙伴們可以參考一下
    2016-03-03
  • JavaScript 雙向鏈表操作實(shí)例分析【創(chuàng)建、增加、查找、刪除等】

    JavaScript 雙向鏈表操作實(shí)例分析【創(chuàng)建、增加、查找、刪除等】

    這篇文章主要介紹了JavaScript 雙向鏈表操作,結(jié)合實(shí)例形式分析了JavaScript雙向鏈表的創(chuàng)建、增加、查找、刪除等相關(guān)操作技巧,需要的朋友可以參考下
    2020-04-04
  • JavaScript面試必備之垃圾回收機(jī)制和內(nèi)存泄漏詳解

    JavaScript面試必備之垃圾回收機(jī)制和內(nèi)存泄漏詳解

    垃圾回收機(jī)制和內(nèi)存泄漏是JavaScript面試時(shí)常常問(wèn)到的問(wèn)題,這篇文章就為大家詳細(xì)整理了他們的相關(guān)知識(shí),感興趣的小伙伴可以跟隨小編一起了解一下
    2023-05-05
  • Echarts中X軸/Y軸坐標(biāo)標(biāo)簽顯示不下的問(wèn)題解決

    Echarts中X軸/Y軸坐標(biāo)標(biāo)簽顯示不下的問(wèn)題解決

    本文主要介紹了Echarts中X軸/Y軸坐標(biāo)標(biāo)簽顯示不下的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • 如何編寫(xiě)高質(zhì)量JS代碼(續(xù))

    如何編寫(xiě)高質(zhì)量JS代碼(續(xù))

    本文是如何編寫(xiě)高質(zhì)量JS代碼系列文章的第二篇,前篇文章反響還不錯(cuò),應(yīng)小伙伴們的要求,今天繼續(xù)此系列的文章,有需要的小伙伴參考下。
    2015-02-02
  • 詳解js創(chuàng)建對(duì)象的幾種方法及繼承

    詳解js創(chuàng)建對(duì)象的幾種方法及繼承

    這篇文章主要介紹了js創(chuàng)建對(duì)象的幾種方法及繼承,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • canvas實(shí)現(xiàn)十二星座星空?qǐng)D

    canvas實(shí)現(xiàn)十二星座星空?qǐng)D

    本文主要分享了canvas實(shí)現(xiàn)十二星座星空?qǐng)D的示例代碼。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02

最新評(píng)論