i made allready that kind of function but it makes my game flicker a little
B4X:
sub selectlevel
Dim lv As Int = randomfunction(maxlevels,pnl1.Tag)
end sub
'....
Sub randomfunction(maxint As Int,forbiddennr As Int) As Int
Dim rnd1 As Int = forbiddennr
Do Until rnd1 <> forbiddennr
rnd1 = Rnd(2,maxint)
Loop
Return rnd1
End Sub
and i want load them randomly but i dont want a level appear twice
so i want to avoid the same level will be loaded again
i tried also
B4X:
Dim lv As Int = Rnd(2,maxlevels+1) 'choose random level except of level1 and same level
If lv <> pnl1.Tag Then
pnl2.LoadLayout("level" & (lv))
pnl2.Tag = lv
Else
pnl2.LoadLayout("level" & Min((pnl1.Tag+1),maxlevels))
pnl2.Tag = Min((pnl1.Tag+1),maxlevels)
End If
Put the allowed numbers in an array, then simply pick an item from the array at random. Slower if you only need to do it occasionally, but if you need to do it often and can prepare the array in advance, it will be fast, and it will have a predictable running time, which the loop methods won't.
Dim r As Int
Dim t As Int
Dim levels() As Int=Array As Int(1,2,3,4,5,6,7,8,9,10)
For x=0 To levels.Length-1
r=Rnd(0,levels.Length)
t=levels(r)
levels(r)=levels(x)
levels(x)=t
Next
Log(levels(0))
chances that the levels will be the same in a row az the previous game are very unlikely
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.