Jack N' Poy


In this tutorial, it shows on how to create a computer game named jack n' poy.
Code snippet

  1. Randomizer code


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Randomize()

        Dim x As Integer

        X = (Rnd() * 10) / 3

        If x = 1 Then lblComputer.Text = "PAPER"
        If x = 2 Then lblComputer.Text = "SCISSOR"
        If x = 3 Then lblComputer.Text = "ROCK"
        ctr += 1
        If ctr = 20 Then
            Timer1.Stop()
            ctr = 0
            Evaluate()
        End If
    End Sub

      2. Evaluate winner code


Sub Evaluate()

        Dim x, y As Integer

        If lblComputer.Text = "PAPER" Then x = 1

        If lblComputer.Text = "ROCK" Then x = 2

        If lblComputer.Text = "SCISSOR" Then x = 3


        If txt1.Text = "PAPER" Then y = 1
        If txt1.Text = "ROCK" Then y = 2
        If txt1.Text = "SCISSOR" Then y = 3
        If lblComputer.Text = txt1.Text Then
            MessageBox.Show("COMPUTER: " & lblComputer.Text & vbCr & "YOU: " & txt1.Text & vbCr & _
                           "WINNER: IT'S A DRAW", "RESULT", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If x > y And x - y = 1 Then
            MessageBox.Show("COMPUTER: " & lblComputer.Text & vbCr & "YOU: " & txt1.Text & vbCr & _
                            "WINNER: " & txt1.Text, "RESULT", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If x < y And y - x = 1 Then
            MessageBox.Show("COMPUTER: " & lblComputer.Text & vbCr & "YOU: " & txt1.Text & vbCr & _
                           "WINNER: " & lblComputer.Text, "RESULT", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If x > y And x - y = 2 Then
            MessageBox.Show("COMPUTER: " & lblComputer.Text & vbCr & "YOU: " & txt1.Text & vbCr & _
                           "WINNER: " & lblComputer.Text, "RESULT", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If x < y And y - x = 2 Then
            MessageBox.Show("COMPUTER: " & lblComputer.Text & vbCr & "YOU: " & txt1.Text & vbCr & _
                           "WINNER: " & txt1.Text, "RESULT", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

    End Sub

Programming Language/IDE: Visual Basic.Net/ Visual Studio 2010


Click Here To Download Source Code