lundi 24 septembre 2018

Visual Basic: Slot machine values all return the same values

I have attempted to create a simple slot machine in visual basic windows form creator. Here is my code so far:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim List1 = New String() {"Banana", "Cherry", "Watermelon", "Bell", "Skull", "Apricot"}
        Dim List2 = New String() {"Banana", "Cherry", "Watermelon", "Bell", "Skull", "Apricot"}
        Dim List3 = New String() {"Banana", "Cherry", "Watermelon", "Bell", "Skull", "Apricot"}
        Dim rn1 = New Random()
        Dim rn2 = New Random()
        Dim rn3 = New Random()
        Dim x As Integer = 0
        While x < 30
            Dim Choice = List1(rn1.Next(0, List1.Count))
            Dim Choice2 = List2(rn2.Next(0, List2.Count))
            Dim Choice3 = List3(rn3.Next(0, List3.Count))

            Select Case Choice
                Case "Banana"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Banana
                Case "Cherry"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Cherry
                Case "Watermelon"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Watermelon
                Case "Skull"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Skull
                Case "Apricot"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Apricot
                Case "Bell"
                    Slot1.Image = Fruit_Machine.My.Resources.Resources.Bell
            End Select
            Select Case Choice2
                Case "Banana"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Banana
                Case "Cherry"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Cherry
                Case "Watermelon"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Watermelon
                Case "Skull"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Skull
                Case "Apricot"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Apricot
                Case "Bell"
                    Slot2.Image = Fruit_Machine.My.Resources.Resources.Bell
            End Select
            Select Case Choice3
                Case "Banana"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Banana
                Case "Cherry"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Cherry
                Case "Watermelon"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Watermelon
                Case "Skull"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Skull
                Case "Apricot"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Apricot
                Case "Bell"
                    Slot3.Image = Fruit_Machine.My.Resources.Resources.Bell
            End Select

            x = x + 1
            Application.DoEvents()
        End While
    End Sub

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

    End Sub
End Class

This does work: each outcome of the slot machine is randomised... to an extent. I am aware that the code is overcomplicated but this is simply a test project and nothing that anyone else is going to see. Being new to VB I understand that this code is probably... messy. However, the main issue arises when the results of the fruit machine show that all 3 slots are the same value. I.E.

This displays that the result is all 3 skulls

I need a solution to this. Any ideas?




Aucun commentaire:

Enregistrer un commentaire