在线剪接阵列进度

发布于 2025-01-27 05:39:03 字数 1933 浏览 2 评论 0原文

这是用于刮擦卡游戏的JavaScript。到目前为止,我想让一个用户只能刮擦一次游戏。例如,有3个var,因此就像3个单独的用户刮擦之后一样,该数组应为空,并且警报功能将呼叫。现在,我只能使用循环清空数组,我无法弄清楚如何每次尝试使其一个剪接。

var promoCode = '';
var bg1 = 'https://cdn.pixabay.com/photo/2020/06/01/22/23/eye-5248678__340.jpg';
var bg2 = 'http://farm5.static.flickr.com/4017/4717107886_dcc1270a65_b.jpg';
var bg3 = 'http://images6.fanpop.com/image/photos/41500000/adorable-puppies-cute-puppies-41538743-590-393.jpg';


var bgArr = [bg1, bg2, bg3];
for(var i = bgArr.length-1;i>=0;i--){
  selectBG = bgArr.splice(Math.floor(Math.random()*bgArr.length), 1)[0];
  console.log(selectBG);
}



if (selectBG === bg1) {
  promoCode = 'SCRATCH400';
} else if (selectBG === bg2) {
  promoCode = 'SCRATCH500';
} else if (selectBG === bg3) {
  promoCode = 'SCRATCH600';
} else if (bgArr.length === 0) {
  alert("No more voucher, back to main website");
  window.location = 'https://www.google.com/';
}


$('#promo').wScratchPad({
  // the size of the eraser
  size: 70,
  // the randomized scratch image   
  bg: selectBG,
  // give real-time updates
  realtime: true,
  // The overlay image
  fg: 'https://cdn.glitch.com/2c225b7b-6134-4f2b-9842-1d5d060d9cd4%2Foverlay.png',
  // The cursor (coin) image
  'cursor': 'url("https://cdn.glitch.com/2c225b7b-6134-4f2b-9842-1d5d060d9cd4%2Fcoin1.png") 30 30, default',

  scratchMove: function(e, percent) {
    console.log(percent);
    console.log(promoCode);

    // Show the plain-text promo code and call-to-action when the scratch area is 50% scratched
    if ((percent > 50) && (promoCode != '')) {
      $('.promo-container').show();
      $('body').removeClass('not-selectable');
      $('.promo-code').html('Your code is: ' + promoCode);
        var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3');
  audio.play();
    }
  }
});

This is a javascript for a scratch card game. So far I want to make it to have one user can only scratch the game once. There are 3 var for example so it will be like after 3 seperate user scratch it, the array should be empty and the alert function will call out. Now I can only use loop to empty the array and I can't figure out how to make it splice one by one per attempt.

var promoCode = '';
var bg1 = 'https://cdn.pixabay.com/photo/2020/06/01/22/23/eye-5248678__340.jpg';
var bg2 = 'http://farm5.static.flickr.com/4017/4717107886_dcc1270a65_b.jpg';
var bg3 = 'http://images6.fanpop.com/image/photos/41500000/adorable-puppies-cute-puppies-41538743-590-393.jpg';


var bgArr = [bg1, bg2, bg3];
for(var i = bgArr.length-1;i>=0;i--){
  selectBG = bgArr.splice(Math.floor(Math.random()*bgArr.length), 1)[0];
  console.log(selectBG);
}



if (selectBG === bg1) {
  promoCode = 'SCRATCH400';
} else if (selectBG === bg2) {
  promoCode = 'SCRATCH500';
} else if (selectBG === bg3) {
  promoCode = 'SCRATCH600';
} else if (bgArr.length === 0) {
  alert("No more voucher, back to main website");
  window.location = 'https://www.google.com/';
}


$('#promo').wScratchPad({
  // the size of the eraser
  size: 70,
  // the randomized scratch image   
  bg: selectBG,
  // give real-time updates
  realtime: true,
  // The overlay image
  fg: 'https://cdn.glitch.com/2c225b7b-6134-4f2b-9842-1d5d060d9cd4%2Foverlay.png',
  // The cursor (coin) image
  'cursor': 'url("https://cdn.glitch.com/2c225b7b-6134-4f2b-9842-1d5d060d9cd4%2Fcoin1.png") 30 30, default',

  scratchMove: function(e, percent) {
    console.log(percent);
    console.log(promoCode);

    // Show the plain-text promo code and call-to-action when the scratch area is 50% scratched
    if ((percent > 50) && (promoCode != '')) {
      $('.promo-container').show();
      $('body').removeClass('not-selectable');
      $('.promo-code').html('Your code is: ' + promoCode);
        var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3');
  audio.play();
    }
  }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文