當前位置: 首頁>>代碼示例>>C#>>正文


C# Random.GenerateNumber方法代碼示例

本文整理匯總了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);
        }
開發者ID:lemon123456,項目名稱:ksc-archive,代碼行數:25,代碼來源:PhysicsComponent.cs

示例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);
 }
開發者ID:lemon123456,項目名稱:ksc-archive,代碼行數:10,代碼來源:MedicalCrate.cs

示例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);
 }
開發者ID:jakepetroules,項目名稱:ksc-archive,代碼行數:8,代碼來源:GameObject.cs


注:本文中的System.Random.GenerateNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。