2009年2月17日 星期二

Lucky Seven 陣列版本

image

Public Class Form1
    Dim acc, s7
    Dim n(3) As Integer
    Dim lbl(3) As Label

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()
        acc = 1000
        Label4.Text = "$" & acc

        lbl(1) = Label1
        lbl(2) = Label2
        lbl(3) = Label3

        Dim i
        For i = 1 To 3
            lbl(i).Text = i
        Next

        With Label4
            .ForeColor = Color.Red
            .Font = New Font("impact", 20, FontStyle.Regular)
        End With

        For i = 1 To 3
            With lbl(i)
                .ForeColor = Color.Yellow
                .BackColor = Color.Blue
                .Font = New Font("impact", 50, FontStyle.Bold)
            End With
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        play()

        'If acc <= 0 Then
        '    Label4.Text = "$" & acc & Space(5) & "您輸光了!"
        '    Button2.Visible = False
        'End If
    End Sub

    Sub play()
        Dim i
        For i = 1 To 3
            n(i) = Int(Rnd() * 10)
        Next

        For i = 1 To 3
            lbl(i).Text = n(i)
        Next i

        s7 = 0
        For i = 1 To 3
            If n(i) = 7 Then s7 = s7 + 1
        Next

        If s7 = 1 Then acc = acc + 60
        If s7 = 2 Then acc = acc + 600
        If s7 = 3 Then acc = acc + 6000

        acc = acc - 50
        Label4.Text = "$" & acc
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i
        For i = 1 To 10000
            play()
        Next
    End Sub
End Class

沒有留言:

張貼留言