while 循环中的条件被破坏(现在有一个片段)

简单用户

让我们说清楚,while 循环中的条件必须检查新挑战的数量是否还没有完成(如 Challenges.finished 数组中所示),这意味着相同的挑战可以显示几次而不是只显示一次时间(根据需要)如果您发现代码中有任何错误,请告诉我。

var challenges = {
        names: [],
        info: [],
        mascot: [],
        now: [],
        finished: []
    };
challenges.names = ['',
                  'The Best Mess', //1
                  'Pookie Madness', //2
                  'A Cookie for Rookie', //3
                  'Water Party!', //4
                  'You took my hair?!', //5
                  'Too. Much. Pizza.', //6
                  'Love is All', //7
                 'Mop the Deck', //8
                 'Be ya Piate', //9
                 'Treasure Hunter', //10
                 'Spread the Love', //11
                 'You are Arrested!', //12
                 'DINO Four', //13
                 "Viking's Moment", //14
                 "Let me Fly!", //15
                 'Do it Smart', //16
                 'Just a Luck', //17
                 'Sporty', //18
                 'Adopt my Emoji', //19
                 "Hey, it's me!", //20
                 'Me and the Music', //21
                 'Puffle Combo', //22
                 'Richest Pirate', //23
                 'Just Chill', //24
                 'You are BANNED', //25
                 'Merry Walrus', //26
                 'Goo Red!!!', //27
                 'Goo Blue!!!', //28
                 'Oops I did it again', //29
                 "Summer's love", //30
                 'Follow da Arrows', //31
                 'I Call it Magic', //32
                 'Welcome to CPI!', //33
                 'Color Changer', //34
                 'Time to Mine!', //35
                 "Parties' Enemy", //36
                 'Dab on them', //37
                 'Paint Wall', //38
                 'Foody Hunter', //39
                 'Squid ya Say?', //40
                 'May the Force', //41
                 'Mustache Forever', //42
                 'Smart Match', //43
                 'Effects Expert', //44
                 'My Name Jeff', //45
                 'SPOOOOKY', //46
                 'WANTED'], //47
    challenges.info = ['',
                      'Change your hair 2 times', //1
                      'Wear a crown and a teddy bear', //2
                      'Put on a cookie', //3
                      'Put a watery background', //4
                      "Put on Rookie's wig", //5
                      "Eat a pizza while on the stadium", //6
                      "Change to a lovely background", //7
                      "Put on a mop at the Migrator", //8
                      "Wear at least one pirate-y item", //9
                      "Find a treasure!", //10
                      "Put a heart near your emoji", //11
                      "Put on a police hat", //12
                      "Use a dino face", //13
                      "Wear a viking helmet", //14
                      "Change to a clouds background", //15
                      "Remove an item/s using the button", //16
                      "Generate a random item/s", //17
                      "Pick any ball", //18
                      "Go to the Pet Shop", //19
                      'Use the "It\'s Me" background', //20
                      'Put on headphones', //21
                      'Adopt a puffle', //22
                      'Use the most expensive item', //23
                      'Put on Blizzard Beach glasses', //24
                      "Hold Thor's Hammer", //25
                      "Merry Walrus!", //26
                      'Cheer the red team', //27
                      'Cheer the blue team', //28
                      'Use the fart speech bubble', //29
                      'Pick the lovely sun', //30
                      'Pick the map', //31
                      'Pick any potion', //32
                      'Put the "Welcome CPI" background', //33
                      "Change your emoji's color", //34
                      "Put a hard hat", //35
                      "Pop the balloons", //36
                      "Dabs dabs dabs dabs", //37
                      "Pick a spray can and bricks", //38
                      'Pick 3 different CPI food', //39
                      'Pick a squid stick', //40
                      'Pick a lightsaber', //41
                      'Put on a mustache', //42
                      'Put hair and a head item', //43
                      'Add 3 effects to your emoji', //44
                      'Name your emoji Jeff', //45
                      'Wear at least 1 Halloween item', //46
                      'Go to the jail'], //47
    challenges.mascot = ['',
                           'R', //1
                           'R', //2
                           'R', //3
                           'R', //4
                           'R', //5
                           'R', //6
                           'AA', //7
                           'RH', //8
                           'RH', //9
                           'RH', //10
                           'AA', //11
                           'AA', //12
                           'AA', //13
                           'RH', //14
                           'R', //15
                           'AA', //16
                           'RH', //17
                           'AA', //18
                           'RH', //19
                           'R', //20
                           'R', //21
                           'AA', //22
                           'RH', //23
                           'R', //24
                           'AA', //25
                           'R', //26
                           'R', //27
                           'R', //28
                           'RH', //29
                           'AA', //30
                           'RH', //31
                           'RH', //32
                           'RH', //33
                           'AA', //34
                           'RH', //35
                           'R', //36
                           'R', //37
                           'R', //38
                           'RH', //39
                           'RH', //40
                           'RH', //41
                           'AA', //42
                           'AA', //43
                           'AA', //44
                           'R', //45
                           'RH', //46
                           'RH'], //47
    challenges.now = ['', -1, -1, -1],
    challenges.finished = [],
    total = 0;
var random_number, this_id2;

function addChallenge(i) {
    $('.all_daily_challenges').append('<div class=CPI_challenge' + i + 'o' + challenges.now[i] + ' alt=o' + challenges.mascot[challenges.now[i]] + '> </div>');
    var where_to_add = $('.CPI_challenge' + i + 'o' + challenges.now[i]);
    where_to_add.append('<div id=phone_challenge' + i + 'o' + challenges.now[i] + '_symbol_' + challenges.mascot[challenges.now[i]] + '> </div>');
    where_to_add.append('<div id=Challenge_name' + i + 'o' + challenges.now[i] + '>' + challenges.names[challenges.now[i]] + '</div>');
    where_to_add.append('<div id=Challenge_info' + i + 'o' + challenges.now[i] + '>' + challenges.info[challenges.now[i]] + '</div>');
    where_to_add.append('<div id=challenge_progress' + i + 'o' + challenges.now[i] + '>Collect</div>');
}

for (var i = 1; i <= 3; i++) {
    random_number = Math.floor((Math.random() * challenges.names.length) + 1);
    while ($.inArray(random_number, challenges.now) != -1) {
        random_number = Math.floor((Math.random() * challenges.names.length) + 1);
    }
    challenges.now[i] = random_number;
    addChallenge(i)
}

$(document).on('click', '[id^=challenge_progress]', function () {
    this_id = $(this).attr('id');
    this_id = parseInt(this_id.substr(18, 19));
    challenges.finished.push(challenges.now[this_id]);
    random_number = Math.floor((Math.random() * challenges.names.length) + 1);
    while ($.inArray(random_number, challenges.now) != -1 && $.inArray(random_number, challenges.finished) != -1) {
        random_number = Math.floor((Math.random() * challenges.names.length) + 1);
    }
    $('.CPI_challenge' + this_id + 'o' + challenges.now[this_id]).remove()
    challenges.now[this_id] = random_number;
    addChallenge(this_id)
    alert(challenges.finished)
})
.phone_black_screen {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 6;
}

.CPI_phone {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    width: 100%;
    height: 100%;
    background: linear-gradient(#3DB8B6, #abd99b);
}

#cpi_phone_title {
    position: absolute;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    margin: auto;
    width: 100%;
    height: 10%;
    text-align: center;
    background: #fbf7f7;
    color: #548C02;
    font-size: 40px;
    font-family: 'Loyola';
    line-height: 10vh;
    z-index: 5;
}

#CPI_phone_shadow1 {
    position: absolute;
    top: 11%;
    left: 5px;
    width: 15%;
    height: 5%;
    max-width: 300px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

#CPI_phone_shadow2 {
    position: absolute;
    bottom: 11%;
    right: 0;
    width: 50%;
    height: 30%;
    max-width: 500px;
    content: url('Navigation/shadow1.png')
}

#CPI_phone_shadow3 {
    position: absolute;
    bottom: 11%;
    right: 0;
    left: 0;
    top: 10%;
    height: 15%;
    width: 35%;
    max-width: 500px;
    content: url('Navigation/shadow2.png');
    z-index: 10;
}

.CPI_apps {
    position: absolute;
    left: 0;
    right: 0;
    top: 35%;
    bottom: 0;
    margin: auto;
    width: 100%;
    height: 30%;
    width: 90%;
    max-width: 500px;
    background: none;
}

[id^=CPI_app] {
    margin: auto;
}

#exit_phone {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 5vw;
    height: 5.5vw;
    min-width: 30px;
    min-height: 35px;
    max-width: 50px;
    max-height: 55px;
    content: url(Navigation/exit_phone.png);
    cursor: pointer;
    z-index: 10;
}

.CPI_phone_white2 {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    margin: auto;
    width: 100%;
    height: 11%;
    text-align: center;
    background: #fbf7f7;
    color: #548C02;
    font-size: 40px;
    font-family: 'Loyola';
    line-height: 10vh;
    z-index: 6;
    box-shadow: 0 -4px 0 rgba(0, 0, 0, 0.2);
}

#CPI_phone_white2_shadow {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 50%;
    height: 50%;
    max-width: 400px;
    background: gray;
    border-radius: 50%;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

.all_daily_challenges {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 25%;
    top: 0;
    margin: auto;
    width: 98%;
    height: 40%;
    max-height: 300px;
    max-width: 1000px;
    background: #044F63;
    border-radius: 20px;
    z-index: 6;
    overflow: hidden;
    overflow-x: auto;
}

[class^=CPI_challenge] {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto;
    width: 80%;
    height: 90%;
    background: white;
    border-radius: 20px;
    z-index: 6;
    max-width: 350px;
}

[id^=Challenge_info] {
    position: absolute;
    top: 1vh;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 100%;
    height: 30%;
    font-size: 20px;
    text-align: center;
}

[id^=phone_challenge] {
    position: absolute;
    left: -30px;
    top: 10px;
    width: 20vw;
    max-width: 80px;
    height: auto;
}

[id*=symbol_AA] {
    content: url('Phone_Challenges/AuntArctic_PC.png');
}

[id*=symbol_R] {
    content: url('Phone_Challenges/Rookie_PC.png');
    width: 15vw;
    max-width: 65px;
}

[id*=symbol_RH] {
    content: url('Phone_Challenges/Rockhopper_PC.png');
    width: 20vw;
    max-width: 85px;
}


[id^=Challenge_name] {
    position: absolute;
    height: 10%;
    left: 0;
    right: 0;
    bottom: 70%;
    top: 0;
    margin: auto;
    z-index: 7;
    font-family: 'Loyola';
    font-size: 30px;
    text-align: center;
}

#name_CPI_challenge {
    position: absolute;
    height: 10%;
    left: 0;
    right: 0;
    bottom: 70%;
    top: 0;
    margin: auto;
    z-index: 7;
    color: white;
    font-family: 'Loyola';
    font-size: 40px;
    text-align: center;
}

[class^=CPI_challenge1] {
    left: 0%;
}

[class^=CPI_challenge2] {
    left: 95%;
}

[class^=CPI_challenge3] {
    left: 175%;
}

[id^=challenge_progress] {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 60%;
    margin: auto;
    width: 80%;
    height: 20%;
    max-width: 200px;
    position: absolute;
    border-radius: 20px;
    background: #3db8b6;
    box-shadow: 0 4px 0 #2F918F;
    color: white;
    font-size: 25px;
    font-family: 'Loyola';
    text-align: center;
    line-height: 40px;
    cursor: pointer;
    transition: 0.5s;
}

[id^=challenge_progress]:hover {
    transform: translateY(2px);
    background: #2F918F;
    box-shadow: 0 2px 0 #266F6D;
}

[alt=oR] {
    background: #EEED9A;
    box-shadow: 0 5px 0 #C4D181;
    color: #E6984D;
    font-family: 'Rookie';
}

[alt=oAA] {
    background: #FBF9F6;
    box-shadow: 0 5px 0 #5FBA15;
    color: #3F661B;
    font-family: 'Aunt Arctic';
}

[alt=oRH] {
    background: #ECBA67;
    box-shadow: 0 5px 0 #C26241;
    color: #AD6C2F;
    font-family: 'Rockhopper';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='phone_black_screen'>
  <div class='CPI_phone_white'>
    <div id='cpi_phone_title'>
        Emoji Maker Phone
    </div>
    <div id='exit_phone'> </div>
    <div class='CPI_phone'>
        <div id='CPI_phone_shadow1'></div>
        <div id='CPI_phone_shadow2'></div>
        <div id='CPI_phone_shadow3'></div>
    </div>
    <div id='name_CPI_challenge'> Daily Challenges </div>
    <div class='all_daily_challenges'>
    </div>
    <table class='CPI_apps'>
        <tr>
            <td>
                <div id='CPI_app1'></div>
            </td>
        </tr>
    </table>
    <div class='CPI_phone_white2'>
        <div id='CPI_phone_white2_shadow'></div>
    </div>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- begin snippet: js hide: false console: true babel: false -->

奇拉格萨塔帕拉

$('[id^=challenge_progress]').on('click', function() { // your code }用以下功能替换您的点击功能。

$(document).on('click','[id^=challenge_progress]',function(){
  this_id = $(this).attr('id');
  this_id = parseInt(this_id.substr(18, 19));
  challenges.finished.push(challenges.now[this_id]);
  random_number = Math.floor((Math.random() * challenges.names.length) + 1);
  while ($.inArray(random_number, challenges.now) != -1 && $.inArray(random_number, challenges.finished) != -1) {
      random_number = Math.floor((Math.random() * challenges.names.length) + 1);
  } 
  $('.CPI_challenge' + this_id + 'o' + challenges.now[this_id]).remove()
  challenges.now[this_id] = random_number;
  addChallenge(this_id)
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从for(或while)循环中将变量发送到另一个活动

来自分类Dev

PHP在while循环中求和,但有条件

来自分类Dev

如何从JSON数据的while循环中删除php中的最后一个逗号

来自分类Dev

或条件在while循环中python

来自分类Dev

从INSERT到WHILE循环中取最后一个逗号

来自分类Dev

仅显示while循环中来自JavaScript的最后一个值

来自分类Dev

While循环中的条件

来自分类Dev

C#如何在while循环中从另一个类调用void方法

来自分类Dev

Python:如何在while循环中满足两个完全不同的条件中的一个或两个

来自分类Dev

在while循环中如何使用最后一个命令?

来自分类Dev

将类“ last”添加到while循环中数组的最后一个元素

来自分类Dev

调用在Java的另一个循环中创建的变量,以及如何在do ... while循环中具有多个条件

来自分类Dev

C在while循环中分叉[连续检查是否有东西并分叉一个孩子并杀死另一个孩子]

来自分类Dev

sqlsrv_query在while循环中缺少第一个结果

来自分类Dev

虽然在另一个while循环中与MySQL

来自分类Dev

如何从for(或while)循环中将变量发送到另一个活动

来自分类Dev

需要从do / while和多个while循环中返回一个值-C

来自分类Dev

PHP在while循环中求和,但有条件

来自分类Dev

用eof()在while循环中被一个错误关闭

来自分类Dev

在while循环中返回一个字符串

来自分类Dev

在while循环中仅显示未插入另一个表中的记录

来自分类Dev

为什么在while循环中记录一个数字?

来自分类Dev

如果在while循环中否则在第一个循环中定义了测试

来自分类Dev

试图在另一个while循环中获取一个while循环,但是它不能一起工作

来自分类Dev

在另一个while循环中使用while循环输出特定数据

来自分类Dev

Bash:在while循环中放入一个read

来自分类Dev

在另一个while循环中使用while循环时出错

来自分类Dev

在一个 while 循环中的两个嵌套 while 循环之间切换

来自分类Dev

在 while 循环中(与外部)声明一个对象

Related 相关文章

  1. 1

    如何从for(或while)循环中将变量发送到另一个活动

  2. 2

    PHP在while循环中求和,但有条件

  3. 3

    如何从JSON数据的while循环中删除php中的最后一个逗号

  4. 4

    或条件在while循环中python

  5. 5

    从INSERT到WHILE循环中取最后一个逗号

  6. 6

    仅显示while循环中来自JavaScript的最后一个值

  7. 7

    While循环中的条件

  8. 8

    C#如何在while循环中从另一个类调用void方法

  9. 9

    Python:如何在while循环中满足两个完全不同的条件中的一个或两个

  10. 10

    在while循环中如何使用最后一个命令?

  11. 11

    将类“ last”添加到while循环中数组的最后一个元素

  12. 12

    调用在Java的另一个循环中创建的变量,以及如何在do ... while循环中具有多个条件

  13. 13

    C在while循环中分叉[连续检查是否有东西并分叉一个孩子并杀死另一个孩子]

  14. 14

    sqlsrv_query在while循环中缺少第一个结果

  15. 15

    虽然在另一个while循环中与MySQL

  16. 16

    如何从for(或while)循环中将变量发送到另一个活动

  17. 17

    需要从do / while和多个while循环中返回一个值-C

  18. 18

    PHP在while循环中求和,但有条件

  19. 19

    用eof()在while循环中被一个错误关闭

  20. 20

    在while循环中返回一个字符串

  21. 21

    在while循环中仅显示未插入另一个表中的记录

  22. 22

    为什么在while循环中记录一个数字?

  23. 23

    如果在while循环中否则在第一个循环中定义了测试

  24. 24

    试图在另一个while循环中获取一个while循环,但是它不能一起工作

  25. 25

    在另一个while循环中使用while循环输出特定数据

  26. 26

    Bash:在while循环中放入一个read

  27. 27

    在另一个while循环中使用while循环时出错

  28. 28

    在一个 while 循环中的两个嵌套 while 循环之间切换

  29. 29

    在 while 循环中(与外部)声明一个对象

热门标签

归档