• 舒尔特方格


    舒尔特方格
    <script>
    window.onload=function(){
        var list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
        var new_list = [];
        while(true){
             if(list.length == 0){
                break;
             }
             var num = parseInt(Math.random()*25+1,10);
             var index = list.indexOf(num);
             if(index == -1){
                continue;
             }
             list.splice(index,1);
             new_list.push(num);
        }
        var table = document.getElementById("table");
        var index = 0;
        for(var i=0;i<5;i++){
            var tr = document.createElement("tr");
            for(var j=0;j<5;j++){
                var td = document.createElement("td");
                var num = document.createTextNode(new_list[index]);
                var button = document.createElement("button");
                var font = document.createElement("font");
                font.setAttribute("size",10);
               
                font.appendChild(num);
                button.appendChild(font);
                button.setAttribute("value",new_list[index]);
                button.setAttribute("style","height:100px;100px");
                td.appendChild(button);
                td.setAttribute("align","center");
                button.setAttribute("onclick","clickEvent(this)");
                tr.appendChild(td);
                 index ++;
            }
            table.appendChild(tr);
        }     
    }
    var arrary = [];
    var time_array = [];
      function clickEvent(obj){
            var num = parseInt(obj.getAttribute("value"));
            if(arrary.length == 0 && num != 1){
                alert("失败!");
                return
            }
            if(num == 1){
                 arrary.push(num);
                var myDate = new Date();
                 var begin = myDate.getSeconds();
                 time_array.push(begin);
            }else{
                if(num==25 && arrary.length==24){
                     var myDate = new Date();
                     var end = myDate.getSeconds();
                     if(parseInt(end) >  time_array[0]){
                         var time = end - time_array[0];
                        alert("success! time:" + time);
                        return
                     }else{
                         var time = end - time_array[0]+60;
                        alert("success! time:" + time);
                        return
                     }
                   
                }
                var lastElement = arrary[arrary.length-1];
                if(num-1 != lastElement){
                    alert("失败!");
                    return
                }
                arrary.push(num);
            }  
        }   
    
    </script>
    
  • 相关阅读:
    C# IL语法
    设计模式学习笔记(1)之单例模式
    设计模式学习笔记(3)之策略设计模式(Strategy)
    ORACLE与SQL SERVER语法区别
    浅谈测试驱动开发(TDD)
    面向对象的5条基本设计原则
    干法读后感磨练灵魂 提升心志
    Linux系统管理之硬盘管理
    Linux硬件信息采集
    Linux iptables
  • 原文地址:https://www.cnblogs.com/RomanticLife/p/9968666.html
Copyright © 2020-2023  润新知