【发布时间】:2012-05-24 10:36:56
【问题描述】:
我有一些代码使用随机数来确定对象是否特殊。我在每个经常重置的 4 个对象上使用此代码。
Random rand = new Random();
int i = rand.Next(1, 25);
if (i == 1)
{
thiss.typer = "boulder";
thiss.texture = Content.Load<Texture2D>("rock");
}
else if (i == 2)
{
thiss.typer = "ice";
thiss.texture = Content.Load<Texture2D>("ice");
}
else if (i == 3)
{
thiss.typer = "bomb";
thiss.texture = Content.Load<Texture2D>("bomb");
}
else
thiss.typer = "normal";
但每次我执行这段代码时,当它创建 4 个对象时,当它使其中一个对象变得特殊时,由于某种原因,它使所有对象都变得特殊。这段代码有什么问题吗,还是我必须展示更多代码才能阐明它?
【问题讨论】: