如何连续三个图像时如何获得警报

时间:2014-09-12 08:35:34

标签: javascript image if-statement

我正在制作一个刮刮卡游戏,如果连续三个相同的img,我想知道如何做到这一点。这是一个代码示例:

    var cleared = 0;
        //scratchpad1
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";        //de plaatjes die je kunt vrij krassen
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer1').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer1").wScratchPad('bg', images[index]);
        $("#nummer1").wScratchPad('fg', 'images/overlay.png');      //de laag die je weg krast
        $("#nummer1").wScratchPad('size', '15');                //grote van het vlak dat je ineens weg krast
        $("#nummer1").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');  //de muis die je hebt boven het krasveld


        //scratchpad2
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer2').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer2").wScratchPad('bg', images[index]);
        $("#nummer2").wScratchPad('fg', 'images/overlay.png');
        $("#nummer2").wScratchPad('size', '15');
        $("#nummer2").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad3
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer3').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer3").wScratchPad('bg', images[index]);
        $("#nummer3").wScratchPad('fg', 'images/overlay.png');
        $("#nummer3").wScratchPad('size', '15');
        $("#nummer3").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad4
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer4').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer4").wScratchPad('bg', images[index]);
        $("#nummer4").wScratchPad('fg', 'images/overlay.png');
        $("#nummer4").wScratchPad('size', '15');
        $("#nummer4").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad5
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer5').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer5").wScratchPad('bg', images[index]);
        $("#nummer5").wScratchPad('fg', 'images/overlay.png');
        $("#nummer5").wScratchPad('size', '15');
        $("#nummer5").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad6
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer6').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer6").wScratchPad('bg', images[index]);
        $("#nummer6").wScratchPad('fg', 'images/overlay.png');
        $("#nummer6").wScratchPad('size', '15');
        $("#nummer6").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad7
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer7').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer7").wScratchPad('bg', images[index]);
        $("#nummer7").wScratchPad('fg', 'images/overlay.png');
        $("#nummer7").wScratchPad('size', '50');
        $("#nummer7").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad8
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer8').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer8").wScratchPad('bg', images[index]);
        $("#nummer8").wScratchPad('fg', 'images/overlay.png');
        $("#nummer8").wScratchPad('size', '50');
        $("#nummer8").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        //scratchpad9
        var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer9').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
                cleared++;
            }
          }
        });
        $("#nummer9").wScratchPad('bg', images[index]);
        $("#nummer9").wScratchPad('fg', 'images/overlay.png');
        $("#nummer9").wScratchPad('size', '50');
        $("#nummer9").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

        if ($("#nummer9").wScratchPad('bg') == $("#nummer7").wScratchPad('bg') &&   $("#nummer8").wScratchPad('bg'))
        {
            window.alert('alle vakjes zijn open gekrast');
            window.location.href="geenprijs.php";
        }

在代码的底部,你会看到一个if语句,我尝试使用它来完成它,但它没有用。

1 个答案:

答案 0 :(得分:2)

如果我和&&&你仍然需要进行比较,例如:

if ($("#nummer9").wScratchPad('bg') == $("#nummer7").wScratchPad('bg') && $("#nummer7").wScratchPad('bg') == $("#nummer8").wScratchPad('bg'))
{
    window.alert('alle vakjes zijn open gekrast');
    window.location.href="geenprijs.php";
}