本文整理汇总了C#中System.Random.GenerateNumber方法的典型用法代码示例。如果您正苦于以下问题:C# Random.GenerateNumber方法的具体用法?C# Random.GenerateNumber怎么用?C# Random.GenerateNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.GenerateNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UsePickaxe
/// <summary>
/// Uses the dwarf's pickaxe to mine the nearest rock.
/// </summary>
public void UsePickaxe()
{
foreach (Rock rock in this.Game.ObjectManager.Objects.Where(p => p is Rock))
{
if (rock.CollisionBounds.IntersectsWith(this.Game.Character.PickaxeBounds))
{
Random random = new Random();
rock.Hitpoints -= random.GenerateNumber(0, this.Game.Character.PickaxeLevel.GetMaximumDamage());
if (rock.Hitpoints == 0 && rock.Ore != OresAndMetals.Boulder)
{
this.Game.RocksCollected[rock.Ore]++;
}
this.Game.Sound.Play(SoundComponent.Sound.Pickaxe);
break;
}
}
this.Game.ObjectManager.Objects.RemoveAll(p => p is Rock && ((Rock)p).IsDestroyed);
}
示例2: MedicalCrate
/// <summary>
/// Initializes a new instance of the <see cref="MedicalCrate"/> class.
/// </summary>
/// <param name="game">Reference to the <see cref="Game"/> instance.</param>
public MedicalCrate(Game game)
: base(game, Resources.medical_crate)
{
Random random = new Random();
this.Healing = random.GenerateNumber(50, 200);
}
示例3: SetCeilingPosition
/// <summary>
/// Sets the object's position so that it is on the ceiling at a random X coordinate on the screen.
/// </summary>
public void SetCeilingPosition()
{
Random random = new Random();
this.Location = new Point(random.GenerateNumber(0, this.Game.ScreenSize.Width - this.Size.Width), 0 - this.Size.Height);
}