[HELP] shuffle buttons with value

  • Thread starter Thread starter Salar Music
  • Start date Start date
S

Salar Music

Guest
hi guys,,

i maked small game

first: i will write my players name in TextBox

1606905.png

after that i will press in button ( Start Game )

he will open second form


1606906.png

i add array and this array have ( 100 fruits ) the game will give me random 16 fruits

i need put my players name inside this fruits images randomly, and when i press on any fruit image

he will open other form and show me name player


1606907.png


my code

Public Class Home

Dim rand As New Random
Dim ButtCount As Integer = 100
Dim fruits(100) As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

fruits(0) = "أفوكادو"
fruits(1) = "بطيخ"
fruits(2) = "برتقال"
fruits(3) = "برقوق"
fruits(4) = "دوريان"
fruits(5) = "عنب أحمر"
fruits(6) = "فيجوة"
fruits(7) = "فراولة"
fruits(8) = "جوز الهند"
fruits(9) = "جريب فروت"
fruits(10) = "كرز"
fruits(11) = "خوخ"
fruits(12) = "كيوي"
fruits(13) = "كمثرى"
fruits(14) = "ليتشي"
fruits(15) = "مانجو"
fruits(16) = "موز"
fruits(17) = "تمر"
fruits(18) = "تين"
fruits(19) = "تفاح أخضر"
fruits(20) = "توت أحمر"
fruits(21) = "توت أسود"
fruits(22) = "توت أزرق"
fruits(23) = "يوسفي"
fruits(24) = "أناناس "
fruits(25) = "شمام"
fruits(26) = "مشمش"
fruits(27) = "بابايا"
fruits(28) = "رمان"
fruits(29) = "تفاح أحمر"
fruits(30) = "عنب أخضر"
fruits(31) = "يقطين"
fruits(32) = "كنتالوب"
fruits(33) = "كاكا"
fruits(34) = "جوافة"
fruits(35) = "قصب"
fruits(36) = "نبق"
fruits(37) = "بندق"
fruits(38) = "فستق"
fruits(39) = "جوز"
fruits(40) = "لوز"
fruits(41) = "كاجو"
fruits(42) = "سوداني"
fruits(43) = "بصل"
fruits(44) = "بطاطس"
fruits(45) = "باذنجان"
fruits(46) = "بازلاء"
fruits(47) = "فلفل رومي"
fruits(48) = "جزر"
fruits(49) = "خرشوف"
fruits(50) = "ليمون أخضر"
fruits(51) = "ليمون أصفر"
fruits(52) = "شطة حمراء"
fruits(53) = "طماطم"
fruits(54) = "كوسة"
fruits(55) = "فطر"
fruits(56) = "بنجر"
fruits(57) = "بروكلي"
fruits(58) = "كابوتشي"
fruits(59) = "فلفل أخضر"
fruits(60) = "خس"
fruits(61) = "خيار"
fruits(62) = "كرنب"
fruits(63) = "زيتون"
fruits(64) = "قرنبيط"
fruits(65) = "ثوم"
fruits(66) = "ذرة"
fruits(67) = "زنجبيل"
fruits(68) = "جرجير"
fruits(69) = "فجل"
fruits(70) = "بن"
fruits(71) = "فول"
fruits(72) = "لوبيا"
fruits(73) = "باميا"
fruits(74) = "نعناع"
fruits(75) = "كرفس"
fruits(76) = "سبانخ"
fruits(77) = "قمح"
fruits(78) = "زعتر"
fruits(79) = "ورق غار"
fruits(80) = "روزماري"
fruits(81) = "عدس"
fruits(82) = "قلقاس"
fruits(83) = "بقدونس"
fruits(84) = "شبث"
fruits(85) = "كراث"
fruits(86) = "ريحان"
fruits(87) = "كزبرة"
fruits(88) = "قرفة"
fruits(89) = "قرنفل"
fruits(90) = "قشطة"
fruits(91) = "ورق عنب"
fruits(92) = "فاصوليا"
fruits(93) = "حمص"
fruits(94) = "بيتايا"
fruits(95) = "هيل"
fruits(96) = "كستناء"
fruits(97) = "لونجان"
fruits(98) = "النجمة"
fruits(99) = "يانسون"

' Fill Button Tags
FillNumbers()

End Sub

Function DlookupFruit(ByVal i As Integer) As String
Return fruits(i)
End Function

Sub FillNumbers()
Dim s As List(Of Integer) = GetRand(1, ButtCount, ButtCount)
Dim counter As Integer = 0
For Each c As Control In Controls
If c.GetType = GetType(Button) And c.Name.StartsWith("btn_") Then
If c.Text = Nothing Then
c.Tag = s.Item(counter)
counter += 1
AddHandler c.Click, AddressOf MultiButton
AddHandler c.MouseHover, AddressOf MultiButtonHover
AddHandler c.MouseLeave, AddressOf MultiButtonLeave
End If
End If
Next
ReNameAllButton()
End Sub

Sub ReNameAllButton()
For Each c As Control In Controls
If c.GetType = GetType(Button) And c.Name.StartsWith("btn_") Then
c.Text = DlookupFruit(c.Tag)
c.BackgroundImage = Image.FromFile(Application.StartupPath & "\Files\" & c.Tag.ToString & ".png")
End If
Next
End Sub

Function GetRand(smallest As Integer, largest As Integer, tk As Integer) As List(Of Integer)
Return Enumerable.Range(smallest, largest - smallest + 1).OrderBy(Function(n) rand.Next).Take(tk).ToList
End Function

Private Sub MultiButtonLeave(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
b.ForeColor = Color.White
End Sub

Private Sub MultiButtonHover(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
b.ForeColor = Color.Black
End Sub

Private Sub MultiButton(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
b.Visible = False
End Sub

Private Sub Home_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
End
End Sub
End Class




this example of my game:

حرب الفواكه

Continue reading...
 
Back
Top