【发布时间】:2016-01-03 22:22:31
【问题描述】:
我正在 VB.net 控制台中制作一个简单的基于文本的冒险,其中包括战斗。在战斗场景中,我希望游戏生成一个随机数来确定你受到的伤害。 这是我当前的代码:
Module Module1
Dim rng As New Random
Dim strmod As Integer = 1
Dim yourhit As Integer
Sub Main()
Console.WriteLine("Welocome to the training grounds!")
yourhit = (rng.Next(1, 4) + strmod)
Console.WriteLine("You hit the dummy and deal {0} damage to it!",
yourhit)
End Sub
End Module
现在我想知道我的随机生成的数字是否可以在不输入另一个变量(在本例中为 yourhit 变量)的情况下显示。我试过简单地用 rng 而不是 yourhit 但有一条消息说 You hit the dummy 并对其造成 System.Random 伤害!
我是 Visual Basic 的新手,因此我们将不胜感激!
【问题讨论】:
标签: vb.net random numbers basic