Código fuente – Curso Visual Basic.Net

Public Class frmGame
    Dim CoorX(500), CoorY(500) As Integer                   'X horizontal y Y Vertical
    Dim Movi As Byte
    Dim MoviAnt As Byte
    Dim LON As Short
    Dim body(499) As Label
    Dim lineaM(21) As String
    Dim block As PictureBox
    Dim Map(29, 21) As Char
    Dim MapSelect As Integer = 0
    Dim Validar_btnAudio As Boolean = False
    Dim ArrayAlimento(6) As Image
    Dim RandomAlimento As New Random
    Dim ArrayPj(6, 5) As Image
    Dim ArrayMap(4) As Image
    Dim Position As Integer = 0
    Dim ContNumPj As Integer = 0
    Dim ContNumMap As Integer = 0

    Private Sub frmGame_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Try
            For A As Short = 0 To 499
                body(A).Dispose()
                body(A) = Nothing
            Next A

            clear_block()

        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf &
                                                ex.Message & vbCrLf & vbCrLf &
                                                "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf &
                       ex.ToString, MsgBoxStyle.Information)
            End If

        End Try
    End Sub

    Private Sub frmGame_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lblTitle.Text = Text
        Me.ClientSize = New Size(900, 697)
        create_body()
        Star_Game()
        Map_Starter()
        'boot_screen()
        Asig_Matriz()

        Select_PJ()

        lblScoreRecord.Text = Format(My.Settings.ScoreRecordPT, "000")

    End Sub

    Private Sub frmGame_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
        If e.KeyCode = Keys.Right And MoviAnt <> 2 Then Movi = 1
        If e.KeyCode = Keys.Left And MoviAnt <> 1 Then Movi = 2
        If e.KeyCode = Keys.Down And MoviAnt <> 4 Then Movi = 3
        If e.KeyCode = Keys.Up And MoviAnt <> 3 Then Movi = 4

        If e.KeyCode = Keys.D And MoviAnt <> 2 Then Movi = 1
        If e.KeyCode = Keys.A And MoviAnt <> 1 Then Movi = 2
        If e.KeyCode = Keys.S And MoviAnt <> 4 Then Movi = 3
        If e.KeyCode = Keys.W And MoviAnt <> 3 Then Movi = 4

        MoviAnt = Movi

        If pnlGameOver.Visible = True And e.KeyCode = Keys.Enter Then Star_Game()

    End Sub



    Private Sub tmrSnake_Tick(sender As Object, e As EventArgs) Handles tmrSnake.Tick

        'Colocamos los Arrays del cuerpo de la Serpiente
        For A As Short = LON To 1 Step -1
            CoorX(A) = CoorX(A - 1)
            CoorY(A) = CoorY(A - 1)
            body(A - 1).SetBounds(CoorX(A), CoorY(A), body(A - 1).Width, body(A - 1).Height)
        Next A

        If Movi = 1 Then CoorX(0) += 30 : lblSnake.Image = ArrayPj(Position, 1) : lblColaSnake.Image = My.Resources.snake_cola_R
        If Movi = 2 Then CoorX(0) -= 30 : lblSnake.Image = ArrayPj(Position, 2) : lblColaSnake.Image = My.Resources.snake_cola_L
        If Movi = 3 Then CoorY(0) += 30 : lblSnake.Image = ArrayPj(Position, 3) : lblColaSnake.Image = My.Resources.snake_cola_DW
        If Movi = 4 Then CoorY(0) -= 30 : lblSnake.Image = ArrayPj(Position, 4) : lblColaSnake.Image = My.Resources.snake_cola_UP

        'Label1.Text = "CoorX " & CoorX(0)
        'Label2.Text = "CoorY " & CoorY(0)
        'Label3.Text = "LON " & Format(LON, "000")

        'Comprobar interacción de la serpiente con Ella
        For A As Short = 1 To LON
            If CoorX(0) = CoorX(A) And CoorY(0) = CoorY(A) Then
                tmrSnake.Enabled = False

                My.Computer.Audio.Play(My.Resources.Muere, AudioPlayMode.Background)

                pnlGameOver.Visible = True
                pnlGameOver.Location = New Point(244, 211)


                If LON > My.Settings.ScoreRecordPT Then
                    My.Settings.ScoreRecordPT = Format(LON, "000")
                    lblScoreRecord.Text = Format(My.Settings.ScoreRecordPT, "000")
                End If
                Exit Sub
            End If
        Next A

        'Comprobar interacción de la serpiente con Bloques
        'For A As Short = 1 To LON
        If Map(CoorX(0) / 30, CoorY(0) / 30) <> " " Then
            tmrSnake.Enabled = False

            My.Computer.Audio.Play(My.Resources.Muere, AudioPlayMode.Background)

            pnlGameOver.Visible = True
            pnlGameOver.Location = New Point(244, 211)

            If LON > My.Settings.ScoreRecordPT Then
                My.Settings.ScoreRecordPT = Format(LON, "000")
                lblScoreRecord.Text = Format(My.Settings.ScoreRecordPT, "000")
            End If
            Exit Sub
        End If
        'Next A

        If CoorX(0) = -30 And CoorY(0) = 270 Then CoorX(0) = 870 : CoorY(0) = 270
        If CoorX(0) = -30 And CoorY(0) = 300 Then CoorX(0) = 870 : CoorY(0) = 300

        If CoorX(0) = 900 And CoorY(0) = 270 Then CoorX(0) = 0 : CoorY(0) = 270
        If CoorX(0) = 900 And CoorY(0) = 300 Then CoorX(0) = 0 : CoorY(0) = 300

        'Colocar la comida
        If lblComida.Visible = False Then Add_Alimento()

        'Comprobar interacción de la serpiente con la comida
        If CoorX(0) = lblComida.Location.X And
            CoorY(0) = lblComida.Location.Y Then
            Try
                If Val(lblComida.Text + 1) = 100 Then
                    lblComida.Text = 1
                Else
                    lblComida.Text = Val(lblComida.Text + 1)
                End If

                'Agregar Cuerpo a la serpiente
                LON += 1
                CoorX(LON) = CoorX(LON - 1)             'Valor X del cuerpo nuevo
                CoorY(LON) = CoorY(LON - 1)             'Valor Y del cuerpo nuevo

                'Colocar el Cuerpo

                body(LON - 1).SetBounds(CoorX(LON), CoorY(LON), body(LON - 1).Width, body(LON - 1).Height)
                body(LON - 1).Visible = True
                lblComida.Visible = False

                body(LON - 1).SetBounds(CoorX(LON), CoorY(LON), body(LON - 1).Width, body(LON - 1).Height)

                lblColaSnake.SetBounds(CoorX(LON), CoorY(LON), body(LON - 1).Width, body(LON - 1).Height)

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

            'Agregar puntos 
            My.Computer.Audio.Play(My.Resources.Come_fruta, AudioPlayMode.Background)
            lblPoint.Text = Format(LON, "000")


        End If

        lblSnake.SetBounds(CoorX(0), CoorY(0), lblSnake.Width, lblSnake.Height)


        If Movi = 1 Then
            lblColaSnake.SetBounds(CoorX(0) - 30, CoorY(LON), lblColaSnake.Width, lblColaSnake.Height)
        ElseIf Movi = 2 Then
            lblColaSnake.SetBounds(CoorX(0) + 30, CoorY(LON), lblColaSnake.Width, lblColaSnake.Height)
        ElseIf Movi = 3 Then
            lblColaSnake.SetBounds(CoorX(0), CoorY(LON) - 30, lblColaSnake.Width, lblColaSnake.Height)
        ElseIf Movi = 4 Then
            lblColaSnake.SetBounds(CoorX(0), CoorY(LON) + 30, lblColaSnake.Width, lblColaSnake.Height)
        End If


    End Sub

#Region "PROCEDIMIENTOS"


    Private Sub Star_Game()
        Try
            For A As Short = 0 To LON
                body(A).Visible = False
            Next A

            LON = 0

            If ContNumMap = 4 Then
                CoorX(0) = 450 : CoorY(0) = 510
                lblSnake.Location = New Point(CoorX(0), CoorY(0))
                lblColaSnake.Location = New Point(CoorX(0) - 30, CoorY(0))
            Else
                CoorX(0) = 180 : CoorY(0) = 300
                lblSnake.Location = New Point(CoorX(0), CoorY(0))
                lblColaSnake.Location = New Point(CoorX(0) - 30, CoorY(0))

            End If





            lblSnake.Image = ArrayPj(Position, 1)
            lblColaSnake.Image = My.Resources.snake_cola_R

            lblComida.Visible = False
            lblComida.Text = 1

            Movi = 0 : MoviAnt = 0

            pnlGameOver.Visible = False

            lblPoint.Text = Format(LON, "000")

            tmrSnake.Enabled = True
        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Information)
            End If
        End Try
    End Sub

    Private Sub create_body()
        For A As Short = 0 To 499
            body(A) = New Label
            body(A).AutoSize = False
            body(A).Size = New Size(30, 30)
            body(A).Image = My.Resources.body0
            body(A).BackColor = Color.Transparent

            Me.pnlPlay.Controls.Add(Me.body(A))
            body(A).Visible = False
        Next A
    End Sub

    Private Sub Create_Block(COL As Short, corX As Short, corY As Short)
        block = New PictureBox
        block.Size = New Size(30, 30)
        If COL = 1 Then block.Image = My.Resources.block1
        If COL = 2 Then block.Image = My.Resources.block2
        If COL = 3 Then block.Image = My.Resources.block3
        If COL = 4 Then block.Image = My.Resources.block4
        block.BackColor = Color.Transparent
        block.Location = New Point(corX, corY)
        Me.pnlPlay.Controls.Add(block)
    End Sub

    Private Sub Asig_Matriz()
        Dim x, y As Short

        'Leer valores X,Y

        For x = 0 To 29                                 '30 Columnas X 
            For y = 0 To 21                             '22 Filas Y

                Map(x, y) = Mid(lineaM(y), x + 1, 1)

            Next y
        Next x

        'Colocar la estructura de los mapas
        For x = 0 To 29                                 '30 Columnas X
            For y = 0 To 21                             '22 Filas Y
                If Map(x, y) = "N" Then Create_Block(1, x * 30, y * 30)
                If Map(x, y) = "A" Then Create_Block(2, x * 30, y * 30)
                If Map(x, y) = "R" Then Create_Block(3, x * 30, y * 30)
                If Map(x, y) = "S" Then Create_Block(4, x * 30, y * 30)
            Next y
        Next x

    End Sub

    Private Sub clear_block()

        For B As Short = 1 To 10
            For Each Controles In Me.pnlPlay.Controls
                If TypeOf Controles Is PictureBox Then
                    Controles.dispose()
                End If
            Next Controles
        Next B
    End Sub

    Private Function load_Alimento()

        ArrayAlimento(0) = My.Resources.pinia
        ArrayAlimento(1) = My.Resources.limon
        ArrayAlimento(2) = My.Resources.naranja
        ArrayAlimento(3) = My.Resources.patilla
        ArrayAlimento(4) = My.Resources.pera
        ArrayAlimento(5) = My.Resources.uva
        ArrayAlimento(6) = My.Resources.uvas

        Dim MyNum As Integer = RandomAlimento.Next(0, 7)

        Return ArrayAlimento(MyNum)


    End Function

    Private Sub Add_Alimento()
        Randomize()
        Dim CoorNX, CoorNY As Integer
        Dim SwPaso As Boolean = False


        Do
            CoorNX = Int(30 * Rnd() + 0)
            CoorNY = Int(22 * Rnd() + 0)
            If Map(CoorNX, CoorNY) = " " Then
                SwPaso = True
            End If

            For A As Short = 0 To LON
                If (CoorNX * 30) = CoorX(A) And (CoorNY * 30) = CoorY(A) Then
                    SwPaso = False
                End If
            Next A

        Loop Until SwPaso = True

        lblComida.Location = New Point(CoorNX * 30, CoorNY * 30)



        lblComida.Image = load_Alimento()

        lblComida.Visible = True
    End Sub

    Private Sub Select_PJ()

        ArrayPj(0, 0) = My.Resources.snakes_green
        ArrayPj(0, 1) = My.Resources.snakes_green_r
        ArrayPj(0, 2) = My.Resources.snakes_green_l
        ArrayPj(0, 3) = My.Resources.snakes_green_dw
        ArrayPj(0, 4) = My.Resources.snakes_green_up

        ArrayPj(1, 0) = My.Resources.snakes_pink
        ArrayPj(1, 1) = My.Resources.snakes_pink_r
        ArrayPj(1, 2) = My.Resources.snakes_pink_l
        ArrayPj(1, 3) = My.Resources.snakes_pink_dw
        ArrayPj(1, 4) = My.Resources.snakes_pink_up

        ArrayPj(2, 0) = My.Resources.snakes_red
        ArrayPj(2, 1) = My.Resources.snakes_red_r
        ArrayPj(2, 2) = My.Resources.snakes_red_l
        ArrayPj(2, 3) = My.Resources.snakes_red_dw
        ArrayPj(2, 4) = My.Resources.snakes_red_up

        ArrayPj(3, 0) = My.Resources.snakes_white
        ArrayPj(3, 1) = My.Resources.snakes_white_r
        ArrayPj(3, 2) = My.Resources.snakes_white_l
        ArrayPj(3, 3) = My.Resources.snakes_white_dw
        ArrayPj(3, 4) = My.Resources.snakes_white_up

        ArrayPj(4, 0) = My.Resources.snakes_black
        ArrayPj(4, 1) = My.Resources.snakes_black_r
        ArrayPj(4, 2) = My.Resources.snakes_black_l
        ArrayPj(4, 3) = My.Resources.snakes_black_dw
        ArrayPj(4, 4) = My.Resources.snakes_black_up

        ArrayPj(5, 0) = My.Resources.snakes
        ArrayPj(5, 1) = My.Resources.snake_R
        ArrayPj(5, 2) = My.Resources.snake_L
        ArrayPj(5, 3) = My.Resources.snake_DW
        ArrayPj(5, 4) = My.Resources.snake_UP

        pctPJ.Image = ArrayPj(0, 0)
        lblSnake.Image = ArrayPj(Position, 1)
    End Sub

    Private Sub SelectMap()
        ArrayMap(0) = My.Resources.Map_Starter
        ArrayMap(1) = My.Resources.mapa_2
        ArrayMap(2) = My.Resources.mapa_3
        ArrayMap(3) = My.Resources.mapa_4
        ArrayMap(4) = My.Resources.boot_screen
        pctMap.Image = ArrayMap(ContNumMap)
    End Sub



    Private Sub Map_Starter()
        tmrSnake.Interval = 200
        pnlPlay.BackgroundImage = My.Resources.fondo
        lineaM(0) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        lineaM(1) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        lineaM(2) = "AA                          AA"
        lineaM(3) = "AA                          AA"
        lineaM(4) = "AA                          AA"
        lineaM(5) = "AA                          AA"
        lineaM(6) = "AA                          AA"
        lineaM(7) = "AA       AAAAAAAAAAA        AA"
        lineaM(8) = "AA                          AA"
        lineaM(9) = "AA                          AA"
        lineaM(10) = "AA                          AA"
        lineaM(11) = "AA                          AA"
        lineaM(12) = "AA                          AA"
        lineaM(13) = "AA                          AA"
        lineaM(14) = "AA       AAAAAAAAAAA        AA"
        lineaM(15) = "AA                          AA"
        lineaM(16) = "AA                          AA"
        lineaM(17) = "AA                          AA"
        lineaM(18) = "AA                          AA"
        lineaM(19) = "AA                          AA"
        lineaM(20) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        lineaM(21) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    End Sub

    Private Sub mapa_2()
        tmrSnake.Interval = 150
        pnlPlay.BackColor = Color.FromArgb(0, 0, 60)
        lineaM(0) = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
        lineaM(1) = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
        lineaM(2) = "RR                          RR"
        lineaM(3) = "RR                          RR"
        lineaM(4) = "RR                          RR"
        lineaM(5) = "RR                          RR"
        lineaM(6) = "RR                          RR"
        lineaM(7) = "RR                          RR"
        lineaM(8) = "RR           R  R           RR"
        lineaM(9) = "RR           R  R           RR"
        lineaM(10) = "RR           R  R           RR"
        lineaM(11) = "RR           R  R           RR"
        lineaM(12) = "RR           R  R           RR"
        lineaM(13) = "RR           R  R           RR"
        lineaM(14) = "RR                          RR"
        lineaM(15) = "RR                          RR"
        lineaM(16) = "RR                          RR"
        lineaM(17) = "RR                          RR"
        lineaM(18) = "RR                          RR"
        lineaM(19) = "RR                          RR"
        lineaM(20) = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
        lineaM(21) = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"

    End Sub

    Private Sub mapa_3()
        tmrSnake.Interval = 100
        pnlPlay.BackgroundImage = Nothing
        pnlPlay.BackColor = Color.FromArgb(64, 64, 64)
        lineaM(0) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
        lineaM(1) = "N                            N"
        lineaM(2) = "N                            N"
        lineaM(3) = "N                            N"
        lineaM(4) = "N                            N"
        lineaM(5) = "N                            N"
        lineaM(6) = "N     AAAAAAAAAAAAAAAAA      N"
        lineaM(7) = "N                            N"
        lineaM(8) = "N                            N"
        lineaM(9) = "NN           NNNN           NN"
        lineaM(10) = "NN           NNNN           NN"
        lineaM(11) = "NN           NNNN           NN"
        lineaM(12) = "NN           NNNN           NN"
        lineaM(13) = "N                            N"
        lineaM(14) = "N                            N"
        lineaM(15) = "N     AAAAAAAAAAAAAAAAA      N"
        lineaM(16) = "N                            N"
        lineaM(17) = "N                            N"
        lineaM(18) = "N                            N"
        lineaM(19) = "N                            N"
        lineaM(20) = "N                            N"
        lineaM(21) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
    End Sub

    Private Sub mapa_4()
        pnlPlay.BackgroundImage = Nothing
        pnlPlay.BackColor = Color.FromArgb(0, 64, 64)
        lineaM(0) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
        lineaM(1) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
        lineaM(2) = "NN                          NN"
        lineaM(3) = "NN  AAAA              AAAA  NN"
        lineaM(4) = "NN  A                    A  NN"
        lineaM(5) = "NN  A                    A  NN"
        lineaM(6) = "NN  A                    A  NN"
        lineaM(7) = "NN                          NN"
        lineaM(8) = "NN       R         R        NN"
        lineaM(9) = "NN       R         R        NN"
        lineaM(10) = "NN       R         R        NN"
        lineaM(11) = "NN       R         R        NN"
        lineaM(12) = "NN       R         R        NN"
        lineaM(13) = "NN                          NN"
        lineaM(14) = "NN                          NN"
        lineaM(15) = "NN  A                    A  NN"
        lineaM(16) = "NN  A                    A  NN"
        lineaM(17) = "NN  A                    A  NN"
        lineaM(18) = "NN  AAAA              AAAA  NN"
        lineaM(19) = "NN                          NN"
        lineaM(20) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
        lineaM(21) = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"
    End Sub

    Private Sub boot_screen()

        tmrSnake.Interval = 200
        pnlPlay.BackColor = Color.SeaGreen
        lineaM(0) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        lineaM(1) = "ARRRRRRRRRRRRRRRRRRRRRRRRRRRRA"
        lineaM(2) = "ARRRRRRRRRRRRRRRRRRRRRRRRRRRRA"
        lineaM(3) = "ARR                        RRA"
        lineaM(4) = "AR                          RA"
        lineaM(5) = "AR NNNNNNNNNNNNNNNNNNNNNNNN RA"
        lineaM(6) = "AR                          RA"
        lineaM(7) = "AR SSSS S  S SSSS S  S SSSS RA"
        lineaM(8) = "AR S    SS S S  S SSS  S    RA"
        lineaM(9) = "AR SSSS SSSS SSSS SS   SSS  RA"
        lineaM(10) = "AR    S S SS S  S S S  S    RA"
        lineaM(11) = "AR SSSS S  S S  S S SS SSSS RA"
        lineaM(12) = "AR                          RA"
        lineaM(13) = "AR NNNNNNNNNNNNNNNNNNNNNNNN RA"
        lineaM(14) = "AR                          RA"
        lineaM(15) = "AR                          RA"
        lineaM(16) = "AR                          RA"
        lineaM(17) = "AR                          RA"
        lineaM(18) = "AR                          RA"
        lineaM(19) = "ARR                        RRA"
        lineaM(20) = "ARRRRRRRRRRRRRRRRRRRRRRRRRRRRA"
        lineaM(21) = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    End Sub

#End Region

#Region "BOTONES"

    Private Sub btnMenu_Click(sender As Object, e As EventArgs) Handles btnMenu.Click

        If Movi = 0 Then
            btnMapChanged.Enabled = True
            btnChangedPj.Enabled = True
            trbSpy.Enabled = True
        Else
            btnMapChanged.Enabled = False
            btnChangedPj.Enabled = False
            trbSpy.Enabled = False
        End If

        If Movi <> 0 Then
            btnReset.Enabled = True
        Else
            btnReset.Enabled = False
        End If

        pnlMenu.Location = New Point(279, 91)
        pnlMenu.Visible = True

        tmrSnake.Enabled = False

    End Sub

    Private Sub btnCloseMenu_Click(sender As Object, e As EventArgs) Handles btnCloseMenu.Click
        pnlMenu.Visible = False

        If pnlGameOver.Visible = False Then
            tmrSnake.Enabled = True
        Else
            tmrSnake.Enabled = False
        End If
    End Sub

    Private Sub btnAudio_Click(sender As Object, e As EventArgs) Handles btnAudio.Click
        If Validar_btnAudio = True Then
            btnAudio.Image = My.Resources.audio_30px
            My.Computer.Audio.Stop()
            Validar_btnAudio = False
        Else
            btnAudio.Image = My.Resources.no_audio_30px
            'My.Computer.Audio.Play()
            Validar_btnAudio = True
        End If

        clear_block()


    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        pnlMenu.Visible = False
        Star_Game()
    End Sub

    Private Sub btnMapChanged_Click(sender As Object, e As EventArgs) Handles btnMapChanged.Click
        pnlMapSelect.Location = New Point(220, 107)
        pnlMapSelect.Visible = True
        pnlMenu.Visible = False
        SelectMap()
    End Sub

    Private Sub btnChangedPj_Click(sender As Object, e As EventArgs) Handles btnChangedPj.Click
        pnlSelectPJ.Location = New Point(313, 221)
        pnlSelectPJ.Visible = True
        pnlMenu.Visible = False

    End Sub

    Private Sub pctGoRPj_Click(sender As Object, e As EventArgs) Handles pctGoRPj.Click

        Try
            If ContNumPj >= 0 And ContNumPj <= 4 Then
                ContNumPj += 1
                pctPJ.Image = ArrayPj(ContNumPj, 0)

            End If

        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf &
                                               ex.Message & vbCrLf & vbCrLf &
                                               "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf &
                       ex.ToString, MsgBoxStyle.Information)
            End If
        End Try
    End Sub

    Private Sub pctGoLPj_Click(sender As Object, e As EventArgs) Handles pctGoLPj.Click
        Try
            If ContNumPj > 0 And ContNumPj <= 5 Then
                ContNumPj -= 1
                pctPJ.Image = ArrayPj(ContNumPj, 0)

            End If

        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf &
                                               ex.Message & vbCrLf & vbCrLf &
                                               "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf &
                       ex.ToString, MsgBoxStyle.Information)
            End If
        End Try
    End Sub

    Private Sub btnSelectPj_Click(sender As Object, e As EventArgs) Handles btnSelectPj.Click
        Position = ContNumPj
        lblSnake.Image = ArrayPj(Position, 1)

        If Position = 5 Then
            lblColaSnake.Visible = True
            lblColaSnake.Location = New Point(CoorX(0) - 30, CoorY(0))
        Else
            lblColaSnake.Visible = False
        End If
    End Sub

    Private Sub pctGoRMap_Click(sender As Object, e As EventArgs) Handles pctGoRMap.Click
        Try
            If ContNumMap >= 0 And ContNumMap <= 3 Then
                ContNumMap += 1

                pctMap.Image = ArrayMap(ContNumMap)
            End If

        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf &
                                               ex.Message & vbCrLf & vbCrLf &
                                               "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf &
                       ex.ToString, MsgBoxStyle.Information)
            End If
        End Try
    End Sub

    Private Sub pctGoLMap_Click(sender As Object, e As EventArgs) Handles pctGoLMap.Click
        Try

            If ContNumMap > 0 And ContNumMap <= 4 Then
                ContNumMap -= 1

                pctMap.Image = ArrayMap(ContNumMap)
            End If

        Catch ex As Exception
            Dim msj As String = MessageBox.Show("Ocurrio el siguiente error: " & vbCrLf & vbCrLf &
                                               ex.Message & vbCrLf & vbCrLf &
                                               "¿Deseas obtener más información?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If msj = DialogResult.Yes Then
                MsgBox("Error:" & vbCrLf & vbCrLf &
                       ex.ToString, MsgBoxStyle.Information)
            End If
        End Try
    End Sub

    Private Sub btnSelectMap_Click(sender As Object, e As EventArgs) Handles btnSelectMap.Click
        MapSelect = ContNumMap
        If MapSelect = 0 Then
            clear_block()
            My.Computer.Audio.Stop()
            Map_Starter()
            Asig_Matriz()
            Star_Game()

            pnlMapSelect.Visible = False
        End If

        If MapSelect = 1 Then
            clear_block()
            My.Computer.Audio.Stop()
            mapa_2()
            Asig_Matriz()
            Star_Game()

            pnlMapSelect.Visible = False
        End If

        If MapSelect = 2 Then
            clear_block()
            My.Computer.Audio.Stop()
            mapa_3()
            Asig_Matriz()
            Star_Game()

            pnlMapSelect.Visible = False
        End If

        If MapSelect = 3 Then
            clear_block()
            My.Computer.Audio.Stop()
            mapa_4()
            Asig_Matriz()
            Star_Game()

            pnlMapSelect.Visible = False
        End If

        If MapSelect = 4 Then
            clear_block()
            My.Computer.Audio.Stop()
            boot_screen()
            Asig_Matriz()
            Star_Game()

            pnlMapSelect.Visible = False
        End If

    End Sub



    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancelPj.Click
        pnlMenu.Visible = True
        pnlSelectPJ.Visible = False
    End Sub

    Private Sub btnCancelMap_Click(sender As Object, e As EventArgs) Handles btnCancelMap.Click
        pnlMenu.Visible = True
        pnlMapSelect.Visible = False
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Beep()
        tmrSnake.Enabled = False
        Dim msj As String = MessageBox.Show("Realmente desea salir del juego", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If msj = DialogResult.Yes Then
            Application.Exit()
        Else
            If pnlGameOver.Visible = False Then
                tmrSnake.Enabled = True
            Else
                tmrSnake.Enabled = False
            End If
        End If

    End Sub

    Private Sub btnContinue_Click(sender As Object, e As EventArgs) Handles btnContinue.Click
        pnlMenu.Visible = False

        If pnlGameOver.Visible = False Then
            tmrSnake.Enabled = True
        Else
            tmrSnake.Enabled = False
        End If
    End Sub

#End Region

    Private Sub trbSpy_Scroll(sender As Object, e As EventArgs) Handles trbSpy.Scroll
        tmrSnake.Interval = trbSpy.Value
    End Sub
End Class
Actualizado 17/10/2021
Actualizado 23/10/2021
Actualizado 27/10/2021

Recursos

https://ouo.io/93vLqEd

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