81/9或25/5或12/6等等..... 这两个数字随机出现。
public SimpleSpriteSequence[] LeftNumbers;
public SimpleSpriteSequence RightNumbers;
public SimpleSpriteSequence NumberResul;
Randomizer NumberSequence = new Randomizer(1, 9);
public void Getnumbers()
{
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
int FirstNumberIndex = NumberSequence.getRandom();
LeftNumbers[0].setCurrentSpriteIndex(FirstNumberIndex);
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
int SecondNumberIndex = NumberSequence.getRandom();
LeftNumbers[1].setCurrentSpriteIndex(SecondNumberIndex);
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
int RightNumberIndex = NumberSequence.getRandom();
RightNumbers.setCurrentSpriteIndex(RightNumberIndex);
int fIndex = 10 * (int)LeftNumbers[0].CurrentSpriteIndex;
int sIndex = (int)LeftNumbers[1].CurrentSpriteIndex;
int Number = fIndex + sIndex;
int lIndex = (int)RightNumbers.CurrentSpriteIndex;
result = Number / lIndex;
Debug.Log(Number + ":" + lIndex + "=" + (Math.Truncate(result)));
while(Math.Truncate(result) >= 10)
{
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
FirstNumberIndex = NumberSequence.getRandom();
LeftNumbers[0].setCurrentSpriteIndex(FirstNumberIndex);
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
SecondNumberIndex = NumberSequence.getRandom();
LeftNumbers[1].setCurrentSpriteIndex(SecondNumberIndex);
if (!NumberSequence.randomRule.hasNumbersLeft())
{
NumberSequence.randomRule.Reset();
}
RightNumberIndex = NumberSequence.getRandom();
RightNumbers.setCurrentSpriteIndex(RightNumberIndex);
fIndex = 10 * (int)LeftNumbers[0].CurrentSpriteIndex;
sIndex = (int)LeftNumbers[1].CurrentSpriteIndex;
Number = fIndex + sIndex;
lIndex = (int)RightNumbers.CurrentSpriteIndex;
result = Number / lIndex;
}}
使用此代码,他们可以获得以下操作: 13:6 = 2或24:7 = 3,依此类推。 如何使用其余0进行操作? 例如:81:9或24:8或12:6等等。 怎么说这个条件?
答案 0 :(得分:3)
您应该使用使用%
作为运算符符号的模运算符。它返回除法的余数,而不是结果。
12 % 6 = 0
21 % 3 = 0
21 % 6 = 3
识别奇数和偶数非常好。