def process_digit_change
return unless active
if Input.repeat?(:UP) || Input.repeat?(:DOWN)
Sound.play_cursor
place = 10 ** (@digits_max - 1 - @index)
n = @number / place % 10
@number -= n * place
n = (n + 1) % 10 if Input.repeat?(:UP)
n = (n + 9) % 10 if Input.repeat?(:DOWN)
@number += n * place
refresh
end
end
改成类似
n = 1 if Input.repeat?(:数字键1)
n = 2 if Input.repeat?(:数字键2)
n = ? if Input.repeat?(:数字键?)
这样
然后套上循环
$i=@digits_max-1 #(我理解应该是比如定义4位,也就是3.2.1.0,最先输入的是3也就是千位,不知道有没有理解错)
begin
..............
$i -=1;
end until $i =0
同时根据i判断n的位数用if来判断n是否需要*10000 *1000 *100 *10
或者用这个,if i >1 n *= 10 ** (@digits_max - 1 - $i) # 是不是指数运算,没理解错吧?