Javascript老虎机错误?

Javascript老虎机错误?,javascript,php,Javascript,Php,我现在正在用JS和PHP编写一种老虎机 我在网上找到了一个脚本,其中包含3个“项目” 所以现在我又增加了一些,但它只对卷盘数组中定义的数字进行计数,而不是对卷盘数组中定义的所有数字进行计数 我的问题是为什么 这是我的密码: <script type="text/javascript"> /* requestAnimationFrame polyfill */ (function(w){ var lastTime = 0, vendors = ['web

我现在正在用JS和PHP编写一种老虎机

我在网上找到了一个脚本,其中包含3个“项目”

所以现在我又增加了一些,但它只对卷盘数组中定义的数字进行计数,而不是对卷盘数组中定义的所有数字进行计数

我的问题是为什么

这是我的密码:

<script type="text/javascript">
/*
    requestAnimationFrame polyfill
*/
(function(w){
    var lastTime = 0,
        vendors = ['webkit', /*'moz',*/ 'o', 'ms'];
    for (var i = 0; i < vendors.length && !w.requestAnimationFrame; ++i){
        w.requestAnimationFrame = w[vendors[i] + 'RequestAnimationFrame'];
        w.cancelAnimationFrame = w[vendors[i] + 'CancelAnimationFrame']
            || w[vendors[i] + 'CancelRequestAnimationFrame'];
    }

    if (!w.requestAnimationFrame)
        w.requestAnimationFrame = function(callback, element){
            var currTime = +new Date(),
                timeToCall = Math.max(0, 16 - (currTime - lastTime)),
                id = w.setTimeout(function(){ callback(currTime + timeToCall) }, timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };

    if (!w.cancelAnimationFrame)
        w.cancelAnimationFrame = function(id){
        clearTimeout(id);
    };
})(this);

/*
    Slot Machine
*/
var sm = (function(undefined){

    var tMax = 3000, // animation time, ms
        height = 210,
        speeds = [],
        r = [],
        reels = [
            ['1',  '2', '3', '4', '5', '6', '7', '8', '9', '0'],
            ['1',  '2', '3', '4', '5', '6', '7', '8', '9', '0'],
            ['1',  '2',  '3', '4', '5', '6', '7', '8', '9', '0']
        ],
        $reels, $msg,
        start;

    function init(){
        $reels = $('.reel').each(function(i, el){
            el.innerHTML = '<div><p>' + reels[i].join('</p><p>') + '</p></div><div><p>' + reels[i].join('</p><p>') + '</p></div>'
        });

        $msg = $('.msg');

        $('button').click(action);
    }

    function action(){
        if (start !== undefined) return;

        for (var i = 0; i < 3; ++i) {
            speeds[i] = Math.random() + .5; 
            r[i] = (Math.random() * 3 | 0) * height / 3;
        }

        $msg.html('Spinning...');
        animate();
    }

    function animate(now){
        if (!start) start = now;
        var t = now - start || 0;

        for (var i = 0; i < 3; ++i)
            $reels[i].scrollTop = (speeds[i] / tMax / 2 * (tMax - t) * (tMax - t) + r[i]) % height | 0;

        if (t < tMax)
            requestAnimationFrame(animate);
        else {
            start = undefined;
            check();
        }
    }

    function check(){
        $msg.html(
            r[0] === r[1] && r[1] === r[2] ?
                'You won! Enjoy your ' + reels[1][ (r[0] / 70 + 1) % 3 | 0 ].split(' ')[0]
            :
                'Try again'
        );
    }

    return {init: init}

})();

$(sm.init);
</script>

/*
requestAnimationFrame多边形填充
*/
(功能(w){
var lastTime=0,
供应商=['webkit'、/*'moz'、*/'o'、'ms'];
对于(var i=0;i')+'

'+reels[i]。加入('

')+'

' }); $msg=$('.msg'); $(“按钮”)。单击(操作); } 函数动作(){ 如果(开始!==未定义)返回; 对于(变量i=0;i<3;++i){ 速度[i]=Math.random()+.5; r[i]=(Math.random()*3 | 0)*高度/3; } $msg.html('Spinning…'); 制作动画(); } 函数动画(现在){ 如果(!start)start=now; var t=now-start | | 0; 对于(变量i=0;i<3;++i) $revels[i].scrollTop=(速度[i]/tMax/2*(tMax-t)*(tMax-t)+r[i])%高度| 0; if(t
我不知道错误在哪里,或者可能在哪里

它只在单轮上显示数字1-4,而不是0-9 这是必须的


我负责哪一部分

如果希望for循环计数到数组中的最大值,则必须告诉它这样做。目前,您仍然将其编码为在3之前停止,因此它就是这样做的。

我将计数器更改为10,现在它完全被窃听了,我必须再次单击每次以稍微移动车轮。。。但同样只显示数字1-5