2015-08-27 124 views
0

我正在构建一个幻想应用程序草稿。由于每10次选中一次,球队就会倒退。有一个简单的方法来做到这一点,或者我需要写一个长的if/else,switch,ext statment吗?递增然后递减10

例如:

  • 皮克队
  • 1 - 1
  • 2 - 2
  • 3 - 3
  • 4 -4
  • 5 - 5
  • 7 - 7
  • 8 - 8
  • 9 - 9
  • 10 - 10
  • 11 - 10
  • 12 - 9
+0

谈谈你的代码? – HelloNewWorld

+0

使用一个变量来保存一个乘数,可以是'+ 1'或'-1'。每当选择是10的倍数时,切换标志。 – Barmar

+1

'10 - | 10 - n |'+'%20' – zerkms

回答

0

使一个布尔变量存储天气我们递增或递减,则一个字节存储您已增加/减少的次数,并进行循环。对布尔值使用if/else。不要忘记每次翻转布尔值。

0

像这样的东西应该把工作做好:

var total_picks = 100; 
var current_pick = 1; 
var current_team = 1; 
var my_test = true; 

for (var i = 0; i < total_picks; i++) { 

    // In this "if" statement, the team number will count up from 1 to 10 
    if (my_test) { 

    // Do whatever you want to with the current pick here 
    current_pick++; 

    // Do whatever you want to with the current team here 
    current_team++; 

    if (current_team == 10) { 
     my_test = false; 
    } 
    } else { 
    // In this "else" statement, the team number will count down from 10 to 1 

    // Do whatever you want to with the current pick here 
    current_pick++; 

    // Do whatever you want to with the current team here 
    current_team--; 
    if (current_team == 0) { 
     my_test = true; 
    } 
    } 
}