Código fuente juego de La Vieja

Curso Visual Basic.Net

Public Class frmPlayLaVieja
    Dim valor As Integer
    Dim btnValue1, btnValue2, btnValue3, btnValue4, btnValue5, btnValue6, btnValue7, btnValue8, btnValue9 As String
    Dim WinsPlayer As String

    Private Sub frmPlayLaVieja_Load(sender As Object, e As EventArgs) Handles Me.Load
        StarGame()
    End Sub

    Private Sub StarGame()
        ptr00.Image = Nothing
        ptr01.Image = Nothing
        ptr02.Image = Nothing
        ptr10.Image = Nothing
        ptr11.Image = Nothing
        ptr12.Image = Nothing
        ptr20.Image = Nothing
        ptr21.Image = Nothing
        ptr22.Image = Nothing

        ptr00.Visible = True
        ptr01.Visible = True
        ptr02.Visible = True
        ptr10.Visible = True
        ptr11.Visible = True
        ptr12.Visible = True
        ptr20.Visible = True
        ptr21.Visible = True
        ptr22.Visible = True

        ptr00.Enabled = True
        ptr01.Enabled = True
        ptr02.Enabled = True
        ptr10.Enabled = True
        ptr11.Enabled = True
        ptr12.Enabled = True
        ptr20.Enabled = True
        ptr21.Enabled = True
        ptr22.Enabled = True

        ptrTable.Visible = True
        ptrWinsPlayer.Visible = False
        lblWinsPlayer.Visible = False
        lblMsj.Visible = False

        WinsPlayer = ""
        btnValue1 = ""
        btnValue2 = ""
        btnValue3 = ""
        btnValue4 = ""
        btnValue5 = ""
        btnValue6 = ""
        btnValue7 = ""
        btnValue8 = ""
        btnValue9 = ""
    End Sub

    Private Sub Clean()
        ptr00.Image = Nothing
        ptr01.Image = Nothing
        ptr02.Image = Nothing
        ptr10.Image = Nothing
        ptr11.Image = Nothing
        ptr12.Image = Nothing
        ptr20.Image = Nothing
        ptr21.Image = Nothing
        ptr22.Image = Nothing

        ptr00.Visible = False
        ptr01.Visible = False
        ptr02.Visible = False
        ptr10.Visible = False
        ptr11.Visible = False
        ptr12.Visible = False
        ptr20.Visible = False
        ptr21.Visible = False
        ptr22.Visible = False

        ptrTable.Visible = False
    End Sub
    Private Sub ptr00_Click(sender As Object, e As EventArgs) Handles ptr00.Click
        valor += 1
        If valor = 1 Then
            ptr00.Image = My.Resources.X
            btnValue1 = "X"
            ptr00.Enabled = False
        ElseIf valor = 2 Then
            ptr00.Image = My.Resources.O
            btnValue1 = "O"
            valor = 0
            ptr00.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr01_Click(sender As Object, e As EventArgs) Handles ptr01.Click
        valor += 1
        If valor = 1 Then
            ptr01.Image = My.Resources.X
            btnValue2 = "X"
            ptr01.Enabled = False
        ElseIf valor = 2 Then
            ptr01.Image = My.Resources.O
            btnValue2 = "O"
            valor = 0
            ptr01.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub frmPlayLaVieja_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
        If ptrWinsPlayer.Visible = True And e.KeyCode = Keys.Enter Then StarGame()
    End Sub

    Private Sub btnQuit_Click(sender As Object, e As EventArgs) Handles btnQuit.Click
        Dim msj As String = MessageBox.Show("Realmente desea salir del juego", "3a Tech", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If msj = DialogResult.Yes Then
            Application.Exit()
        Else

        End If
    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        StarGame()
    End Sub

    Private Sub ptr02_Click(sender As Object, e As EventArgs) Handles ptr02.Click
        valor += 1
        If valor = 1 Then
            ptr02.Image = My.Resources.X
            btnValue3 = "X"
            ptr02.Enabled = False
        ElseIf valor = 2 Then
            ptr02.Image = My.Resources.O
            btnValue3 = "O"
            valor = 0
            ptr02.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr10_Click(sender As Object, e As EventArgs) Handles ptr10.Click
        valor += 1
        If valor = 1 Then
            ptr10.Image = My.Resources.X
            btnValue4 = "X"
            ptr10.Enabled = False
        ElseIf valor = 2 Then
            ptr10.Image = My.Resources.O
            btnValue4 = "O"
            valor = 0
            ptr10.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr11_Click(sender As Object, e As EventArgs) Handles ptr11.Click
        valor += 1
        If valor = 1 Then
            ptr11.Image = My.Resources.X
            btnValue5 = "X"
            ptr11.Enabled = False
        ElseIf valor = 2 Then
            ptr11.Image = My.Resources.O
            btnValue5 = "O"
            valor = 0
            ptr11.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr12_Click(sender As Object, e As EventArgs) Handles ptr12.Click
        valor += 1
        If valor = 1 Then
            ptr12.Image = My.Resources.X
            btnValue6 = "X"
            ptr12.Enabled = False
        ElseIf valor = 2 Then
            ptr12.Image = My.Resources.O
            btnValue6 = "O"
            valor = 0
            ptr12.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr20_Click(sender As Object, e As EventArgs) Handles ptr20.Click
        valor += 1
        If valor = 1 Then
            ptr20.Image = My.Resources.X
            btnValue7 = "X"
            ptr20.Enabled = False
        ElseIf valor = 2 Then
            ptr20.Image = My.Resources.O
            btnValue7 = "O"
            valor = 0
            ptr20.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr21_Click(sender As Object, e As EventArgs) Handles ptr21.Click
        valor += 1
        If valor = 1 Then
            ptr21.Image = My.Resources.X
            btnValue8 = "X"
            ptr21.Enabled = False
        ElseIf valor = 2 Then
            ptr21.Image = My.Resources.O
            btnValue8 = "O"
            valor = 0
            ptr21.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub ptr22_Click(sender As Object, e As EventArgs) Handles ptr22.Click
        valor += 1
        If valor = 1 Then
            ptr22.Image = My.Resources.X
            btnValue9 = "X"
            ptr22.Enabled = False
        ElseIf valor = 2 Then
            ptr22.Image = My.Resources.O
            btnValue9 = "O"
            valor = 0
            ptr22.Enabled = False
        End If

        comprobador()

    End Sub

    Private Sub comprobador()
        If btnValue1 = "X" And btnValue2 = "X" And btnValue3 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        ElseIf btnValue1 = "O" And btnValue2 = "O" And btnValue3 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()
        End If

        If btnValue4 = "X" And btnValue5 = "X" And btnValue6 = "X" Then
                lblWinsPlayer.Text = "X"
                lblWinsPlayer.Visible = True
                lblMsj.Visible = True
                ptrWinsPlayer.Visible = True

                Clean()

            ElseIf btnValue4 = "O" And btnValue5 = "O" And btnValue6 = "O" Then
                lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue7 = "X" And btnValue8 = "X" And btnValue9 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        ElseIf btnValue7 = "O" And btnValue8 = "O" And btnValue9 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue1 = "X" And btnValue4 = "X" And btnValue7 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        ElseIf btnValue1 = "O" And btnValue4 = "O" And btnValue7 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue2 = "X" And btnValue5 = "X" And btnValue8 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        ElseIf btnValue2 = "O" And btnValue5 = "O" And btnValue8 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue3 = "X" And btnValue6 = "X" And btnValue9 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()


        ElseIf btnValue3 = "O" And btnValue6 = "O" And btnValue9 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue1 = "X" And btnValue5 = "X" And btnValue9 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()


        ElseIf btnValue1 = "O" And btnValue5 = "O" And btnValue9 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If

        If btnValue3 = "X" And btnValue5 = "X" And btnValue7 = "X" Then
            lblWinsPlayer.Text = "X"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        ElseIf btnValue3 = "O" And btnValue5 = "O" And btnValue7 = "O" Then
            lblWinsPlayer.Text = "O"
            lblWinsPlayer.Visible = True
            lblMsj.Visible = True
            ptrWinsPlayer.Visible = True

            Clean()

        End If
    End Sub


End Class
Abrir chat
1
💬 Hola ¿Necesita más información?
Hola 👋
¿En que podemos ayudarle?