[HELP] Randomizing

Posts 1–12 of 12 · Page 1 of 1
[HELP] Randomizing
Hey, i'm making an RPG game.
And I want for the button where it says "BATTLE"
to randomize which monster you fight.
Also, I want it to randomize the damage you do.
Can anyone help me? Thanks.
You can use select case?
Code:
Dim rand as random
Select case rand.next(1,*whatever number here*)
Case 1
monster 1
case 2
monster 2
end select
Off the top of my head, there may be some errors of some sort.
rand.next? Not familiar with that.

Code:
Public Function Rand(ByVal Low As Long, _
                     ByVal High As Long) As Long
  Rand = Int((High - Low + 1) * Rnd) + Low
End Function
Then call
Code:
Monster = Rand(MIN#, MAX#)
Example
Code:
Monster = Rand(1, 10)
Returns a number between 1 and 10
Id go with lolland and say use case 1, case 2 etc.
^
He would still need to randomize.
Lolland's way is the best way. Id go with that !!
Numerous ways to randomize, most effective and used (IMO) is Select Case, however it really depends on what you are trying to attempt. Not sure randomizing a monster fight with Select Case is the optimum choice, but functional.
None of those worked for me, the monsters they fight are different forms, I want to know how to randomize your forms.
Just use the select case and instead of just putting

"Monster 2" for case 2 put:

[php]Monster2Form.Show()[/php] or some such code (monster2form is the name of the monster's form
Quote Originally Posted by Jason View Post
Just use the select case and instead of just putting

"Monster 2" for case 2 put:

[php]Monster2Form.Show()[/php] or some such code (monster2form is the name of the monster's form
I find the
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Dim RandomClass As New Random()
        Dim i As Integer
        i = RandomClass.Next(1, 3) 'this will make 'i' either 1 or 2.'
        If i = Val(1) Then
            TextBox1.Text = "I iz pro"
        Else : TextBox1.Text = "I iz newb"
        End If
Works well for this situation as well.

End Sub [/CODE]
Quote Originally Posted by tempta43 View Post
I find the
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Dim RandomClass As New Random()
        Dim i As Integer
        i = RandomClass.Next(1, 3) 'this will make 'i' either 1 or 2.'
        If i = Val(1) Then
            TextBox1.Text = "I iz pro"
        Else : TextBox1.Text = "I iz newb"
        End If
Works well for this situation as well.

End Sub [/CODE]
Haha yes I suppose it would. But if you have a lot of monsters it will get messy with lots of "Elseif i = val(214) then".... etc haha. There is a cleaner method I'll post in a sec when i make sure it works

EDIT: I think select case is your best option rather than elseif + elseif all the time. Makes it easier to find what it going wrong.

do something like this

[php]
Dim RandomNumber as New Random
Dim i as Integer
i = RandomNumber.Next(1, xx) 'with xx being then number of monsters you have +1'

Select Case i

Case 1
'do something here'
Case 2
'do something'
Case 3
'Blahhhhh'
End Select
[/php]

I think that'd be the best option
Posts 1–12 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?