Monday, January 13, 2014

Reset graphic to start position

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnrestart.Click
        piccar1.location = New Point(piccar1.location.x.equals(-1000), piccar1.location.y.equals(0))
        piccar1.top = piccar1.top + 50
        piccar1.left = piccar1.left + btnrestart.enabled = False
        btnrestart.enabled = False
        piccar1.Image = My.Resources.big_black_dot
        lblwin.visible = False
        label1.visible = True
    End Sub

Friday, November 8, 2013

Reading Data from a Resourse Text File

 'FIRST- Make a text file using Notepad and save it in the same
 'folder as your Project

    'MAKE SURE that you don't hit Enter after the Last Data Item
    'in your Notepad file. Name it something like myData.txt 

  'Second:  you MUST setup the resource file- To Do this:      'Choose the Project Tab- Name-Of-the-Project's Properties
          (absolute bottom choice)
      'Choose the Resources Tab on the Left
      'Choose Add Resources
      'It should place the Resource ICON in the Window
      'Now you can use the code below to read the data
          'from the resource text file

Public Class Form1
    'With the following code, words are stored Word(0) to Word(9)
    Dim Word() As String = Split(My.Resources.mywords, vbLf)
    'y generates the Random Number
    Dim y As Integer

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

    End Sub
End Class
    Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
      'y gets a number between 0 and 9
        y = Int(Rnd() * 10)
        lblWord.Text = Word(y)
    End Sub

Read Data from a Text File saved in Resources

    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Randomize()
        '     get the data from text file
        '     This program reads 5 data Items
        '     inFile opens the notepad file
        inFile = IO.File.OpenText("My.Resources.Resource1.words_txt")

        'this function loops around until there is no more data
        Do Until inFile.Peek = -1
            X = X + 1
            'Word(1) stores the first word; Word(2) stores the second word and so forth
            Word(X) = inFile.ReadLine
        Loop
        'you must close the file
        inFile.Close()
    End Sub

    Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
        y = Int(Rnd() * 10) + 1
        lblWord.Text = Word(y)
    End Sub   

Monday, November 4, 2013

Set the starting position of picCar1 or other object using the location command

Private Sub btnNEW_Click(sender As Object, e As EventArgs) Handles btnNEW.Click
picCar1.Location = New Point(picCar1.Location.X.Equals(0), picCar1.Location.Y.Equals(0))
picCar1.Top = picCar1.Top + 50
picCar1.Left = picCar1.Left + 60
 
btnNEW.Enabled = False
btnNEW.Visible = False

picCar1.Image = My.Resources.car1_Right
 End Sub

Tuesday, October 22, 2013

Car goes forward and Hits a Wall

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     picCar1.Left = picCar1.Left + 10

If picCar1.Top < rightBorder.Top + rightBorder.Height And picCar1.Top > rightBorder.Top - picCar1.Height And picCar1.Left < rightBorder.Left + rightBorder.Width And picCar1.Left > rightBorder.Left - picCar1.Width Then
     
Timer1.Enabled = False

 
End If

End Sub

Friday, October 11, 2013

SORT used with Slot Machineto make it easier to detect the 3 bars

Public Class frmMain
    Public counter, x, y, z As Integer
    Public sort(3) As Integer
    Public f, s, w As Integer


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        lblBobSlotMachine.Text = "Bob's Slot Machine"
        Randomize()
        picMoney.Visible = False
        counter = 0
        'Start Dice
        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        x = Int(Rnd() * 7) + 1
        If x = 1 Then
            picBox1.Image = My.Resources.Bar
        ElseIf x = 2 Then
            picBox1.Image = My.Resources.Bar2
        ElseIf x = 3 Then
            picBox1.Image = My.Resources.Bar3
        ElseIf x = 4 Then
            picBox1.Image = My.Resources.Apple
        ElseIf x = 5 Then
            picBox1.Image = My.Resources.Cherry
        ElseIf x = 6 Then
            picBox1.Image = My.Resources.grapes
        Else
            picBox1.Image = My.Resources.seven
        End If

        y = Int(Rnd() * 7) + 1
        If y = 1 Then
            PicBox2.Image = My.Resources.Bar
        ElseIf y = 2 Then
            PicBox2.Image = My.Resources.Bar2
        ElseIf y = 3 Then
            PicBox2.Image = My.Resources.Bar3
        ElseIf y = 4 Then
            PicBox2.Image = My.Resources.Apple
        ElseIf y = 5 Then
            PicBox2.Image = My.Resources.Cherry
        ElseIf y = 6 Then
            PicBox2.Image = My.Resources.grapes
        Else
            PicBox2.Image = My.Resources.seven
        End If
        z = Int(Rnd() * 7) + 1
        If z = 1 Then
            PicBox3.Image = My.Resources.Bar
        ElseIf z = 2 Then
            PicBox3.Image = My.Resources.Bar2
        ElseIf z = 3 Then
            PicBox3.Image = My.Resources.Bar3
        ElseIf z = 4 Then
            PicBox3.Image = My.Resources.Apple
        ElseIf z = 5 Then
            PicBox3.Image = My.Resources.Cherry
        ElseIf z = 6 Then
            PicBox3.Image = My.Resources.grapes
        Else
            PicBox3.Image = My.Resources.seven
        End If
        counter = counter + 1
        If counter = 10 Then
            Winner()
            Timer1.Enabled = False

        End If
    End Sub
    Sub sortItems()
        sort(1) = x
        sort(2) = y
        sort(3) = z
        For f = 1 To 3
            For s = 1 To 2
                If sort(f) < sort(s) Then
                    w = sort(f)
                    sort(f) = sort(s)
                    sort(s) = w
                End If
            Next s
        Next f
        x = sort(1)
        y = sort(2)
        z = sort(3)

    End Sub

    Sub Winner()
        sortItems()
        lblTestx.Text = x
        lbltesty.Text = y
        lblTestz.Text = z

        If x = 1 And y = 2 And z = 3 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If
        If x = 1 And y = 1 And z = 3 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If
        If x = 1 And y = 1 And z = 2 Then
            'all bars - all differnt
            lblBobSlotMachine.Text = "3 different Bars- $800 Winner"
            picMoney.Visible = True
        End If

        If x = 2 And y = 3 And z = 3 Then
                lblBobSlotMachine.Text = "Bars- $800 Winner"
                picMoney.Visible = True
            End If
            If x = 2 And y = 3 And z = 3 Then
                    lblBobSlotMachine.Text = "Bars- $800 Winner"
                    picMoney.Visible = True
                End If

        If x = y And x = z Then
            lblBobSlotMachine.Text = "Bars- $800 Winner"
            picMoney.Visible = True
        End If


                If x = y And x = z Then
                    lblBobSlotMachine.Text = "$800 Winner"
                    picMoney.Visible = True
                End If

                If x = 7 And y = 7 And z = 7 Then
                    lblBobSlotMachine.Text = "$1000 Winner"
                    picMoney.Visible = True
                End If

                If x = 5 Or y = 5 Or z = 5 Then
                    lblBobSlotMachine.Text = "$2 Winner"
                    picMoney.Visible = True
                End If
    End Sub


End Class

Monday, September 9, 2013

Simple Slot Machine- 3 Labels, Button and Money

'Simple Slot Machine
Dim x, y, z As Integer
        Randomize()
picMoney.Visible = False
        x = Int(Rnd() * 7) + 1
        y = Int(Rnd() * 7) + 1
        z = Int(Rnd() * 7) + 1
        lblBox1.Text = x
        lblBox2.Text = y
        lblBox3.Text = z
       If x=7 or y=7 and z= 7 Then
            picMoney.Visible = True
       End If