Anonymní profil Kolega – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil Kolega – Programujte.comAnonymní profil Kolega – Programujte.com

 

Příspěvky odeslané z IP adresy 176.122.32.–

Šmakoun
Visual Basic › Tanková hra pomoc s příkazi
25. 3. 2019   #383346

Heh paráda, hra mě jde ubíraní životů také. 

Mám tedy poslední 2 problémy :)

Tank2 když vystřelí doleva, sekne se kulka chvíli po výstřelu. viz. fotka. Na všechny ostatní směry je to v pořádku je to pro mě docela velký hlavolam. Děkuji všem za radu. PS kod je trochu delší tak neleknout.

Připojen obrázek.

Public Class Form2

    Dim HP1 As Integer = 3
    Dim HP2 As Integer = 3
    Dim konec1 As String
    Dim Msg1 As String = ("Zelený hráč vyhrál! Zkusit znova?")
    Dim konec2 As String
    Dim Msg2 As String = ("Modrý hráč vyhrál!Zkusit znova?")
    Dim X1, Y1, X2, Y2, Smer, Smer2, Xstrela, Xstrela2, Ystrela, Ystrela2, Strela, Strela2, Vystreleno, Vystreleno2, Konecvystrelu, Konecvystrelu2 As Integer

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal klavesa As Keys) As Boolean
        X1 = Me.Tank1.Location.X
        Y1 = Me.Tank1.Location.Y
        X2 = Me.Tank2.Location.X
        Y2 = Me.Tank2.Location.Y


        REM Tank1
        If (Me.Tank1.Location.Y > 41) And ((Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height + 2) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 8) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 1) Or (Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 1)) Then
            If klavesa = Keys.Up Then
                Me.Tank1.Image = Me.Tanknahoru.Image
                Me.Tank1.Height = 29
                Me.Tank1.Width = 24
                Y1 = Y1 - 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 1
            End If
        End If

        If (Me.Tank1.Location.Y < Me.Height - 69) And ((Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 8) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height - 1) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 1) Or (Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 1)) Then
            If klavesa = Keys.Down Then
                Me.Tank1.Image = Me.Tankdolu.Image
                Me.Tank1.Height = 29
                Me.Tank1.Width = 24
                Y1 = Y1 + 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 2
            End If
        End If

        If (Me.Tank1.Location.X > 0) And ((Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width + 2) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 8) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 1) Or (Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 1)) Then
            If klavesa = Keys.Left Then
                Me.Tank1.Image = Me.Tankvlevo.Image
                Me.Tank1.Height = 24
                Me.Tank1.Width = 29
                X1 = X1 - 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 3
            End If
        End If

        If (Me.Tank1.Location.X < Me.Width - 48) And ((Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 8) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width - 1) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 1) Or (Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 1)) Then
            If klavesa = Keys.Right Then
                Me.Tank1.Image = Me.Tankvpravo.Image
                Me.Tank1.Height = 24
                Me.Tank1.Width = 29
                X1 = X1 + 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 4
            End If
        End If

        REM proměnná Vystreleno pro zakázání dalšího výstřelu během letu kulky tanku1
        If Vystreleno = 0 Then
            If klavesa = Keys.Space Then
                Xstrela = Me.Tank1.Location.X
                Ystrela = Me.Tank1.Location.Y
                Strela = Smer
                Timer1.Start()
                Vystreleno = 1
            End If
        End If

        REM proměnná Vystreleno pro zakázání dalšího výstřelu během letu kulky tanku2
        If Vystreleno2 = 0 Then
            If klavesa = Keys.C Then
                Xstrela2 = Me.Tank2.Location.X
                Ystrela2 = Me.Tank2.Location.Y
                Strela2 = Smer2
                Timer3.Start()
                Vystreleno2 = 1
            End If
        End If


        REM Tank2
        If (Me.Tank2.Location.Y > 41) And ((Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height + 2) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 8) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 1) Or (Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 1)) Then
            If klavesa = Keys.W Then
                Me.Tank2.Image = Me.Tank2nahoru.Image
                Me.Tank2.Height = 29
                Me.Tank2.Width = 24
                Y2 = Y2 - 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 5
            End If
        End If

        If (Me.Tank2.Location.Y < Me.Height - 69) And ((Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 8) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height - 1) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 1) Or (Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 1)) Then
            If klavesa = Keys.S Then
                Me.Tank2.Image = Me.Tank2dolu.Image
                Me.Tank2.Height = 29
                Me.Tank2.Width = 24
                Y2 = Y2 + 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 6
            End If
        End If

        If (Me.Tank2.Location.X > 0) And ((Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width + 2) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 8) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 1) Or (Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 1)) Then
            If klavesa = Keys.A Then
                Me.Tank2.Image = Me.Tank2vlevo.Image
                Me.Tank2.Height = 24
                Me.Tank2.Width = 29
                X2 = X2 - 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 7
            End If
        End If

        If (Me.Tank2.Location.X < Me.Width - 48) And ((Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 8) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width - 2) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 1) Or (Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 1)) Then
            If klavesa = Keys.D Then
                Me.Tank2.Image = Me.Tank2vpravo.Image
                Me.Tank2.Height = 24
                Me.Tank2.Width = 29
                X2 = X2 + 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 8
            End If
        End If

        Return MyBase.ProcessCmdKey(msg, klavesa)
    End Function

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Smer = 4
        Smer2 = 7
        Me.BackColor = Color.White
        Vystreleno = 0
        Vystreleno2 = 0
    End Sub


    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        REM strela nahoru
        If Strela = 1 Then
            Me.Kulka.Width = 7
            Me.Kulka.Height = 10
            Me.Kulka.Image = Me.Kulkanahoru.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 9, Ystrela - 19)
            If Me.Kulka.Location.Y < 41 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela - 19)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 3) And (Me.Kulka.Location.X > Me.Tank2.Location.X - 4) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela - 16)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
                Me.HP2 = HP2 - 1
                If HP2 = 2 Then
                    Me.zivot4.Hide()
                End If
                If HP2 = 1 Then
                    Me.zivot5.Hide()
                End If
                If HP2 = 0 Then
                    Me.zivot6.Hide()
                    Me.konec1 = MsgBox("Zelený hráč vyhrál chcete zkusit znova?", vbYesNo)
                    If konec1 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Ystrela = Ystrela - 5
            Strela = 1
        End If

        REM strela dolu
        If Strela = 2 Then
            Me.Kulka.Width = 7
            Me.Kulka.Height = 10
            Me.Kulka.Image = Me.Kulkadolu.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 10, Ystrela + 39)
            If Me.Kulka.Location.Y > Me.Height - 59 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 3, Ystrela + 39)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()

            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka.Location.Y > Me.Tank2.Location.Y - Me.Kulka.Height) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) And (Me.Kulka.Location.X > Me.Tank2.Location.X - 4) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela + 26)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
                Me.HP2 = HP2 - 1
                If HP2 = 2 Then
                    Me.zivot4.Hide()
                End If
                If HP2 = 1 Then
                    Me.zivot5.Hide()
                End If
                If HP2 = 0 Then
                    Me.zivot6.Hide()
                    Me.konec1 = MsgBox(Msg1, vbYesNo)
                    If konec1 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If

                End If
            End If
            Ystrela = Ystrela + 5
            Strela = 2
        End If

        REM strela doleva
        If Strela = 3 Then
            Me.Kulka.Width = 10
            Me.Kulka.Height = 7
            Me.Kulka.Image = Me.Kulkavlevo.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 10)
            If Me.Kulka.Location.X < 3 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 3)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka.Location.X > Me.Tank2.Location.X) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 4) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela - 18, Ystrela + 2)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
                Me.HP2 = HP2 - 1
                If HP2 = 2 Then
                    Me.zivot4.Hide()
                End If
                If HP2 = 1 Then
                    Me.zivot5.Hide()
                End If
                If HP2 = 0 Then
                    Me.zivot6.Hide()
                    Me.konec1 = MsgBox(Msg1, vbYesNo)
                    If konec1 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Xstrela = Xstrela - 5
            Strela = 3
        End If

        REM strela doprava
        If Strela = 4 Then
            Me.Kulka.Width = 10
            Me.Kulka.Height = 7
            Me.Kulka.Image = Me.Kulkavpravo.Image()
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 9)
            If Me.Kulka.Location.X > Me.Width - 38 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 2)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) And (Me.Kulka.Location.X > Me.Tank2.Location.X - Me.Kulka.Width) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 4) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 27, Ystrela + 2)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
                Me.HP2 = HP2 - 1
                If HP2 = 2 Then
                    Me.zivot4.Hide()
                End If
                If HP2 = 1 Then
                    Me.zivot5.Hide()
                End If
                If HP2 = 0 Then
                    Me.zivot6.Hide()
                    Me.konec1 = MsgBox(Msg1, vbYesNo)
                    If konec1 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Xstrela = Xstrela + 5
            Strela = 4
        End If


    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        REM strela nahoru
        If Strela2 = 5 Then
            Me.Kulka2.Width = 7
            Me.Kulka2.Height = 10
            Me.Kulka2.Image = Me.Kulkanahoru2.Image
            Me.Kulka2.Show()
            Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 9, Ystrela2 - 19)
            If Me.Kulka2.Location.Y < 41 Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 - 19)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 3) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - 4) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 - 15)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
                Me.HP1 = HP1 - 1

                If HP1 = 2 Then
                    Me.zivot1.Hide()
                End If
                If HP1 = 1 Then
                    Me.zivot2.Hide()
                End If
                If HP1 = 0 Then
                    Me.zivot3.Hide()
                    Me.konec2 = MsgBox(Msg2, vbYesNo)
                    If konec2 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Ystrela2 = Ystrela2 - 5
            Strela2 = 5
        End If

        REM strela dolu
        If Strela2 = 6 Then
            Me.Kulka2.Width = 7
            Me.Kulka2.Height = 10
            Me.Kulka2.Image = Me.Kulkadolu2.Image
            Me.Kulka2.Show()
            Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 10, Ystrela2 + 39)
            If Me.Kulka2.Location.Y > Me.Height - 59 Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 3, Ystrela2 + 39)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - Me.Kulka2.Height) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - 4) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 + 25)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
                Me.HP1 = HP1 - 1

                If HP1 = 2 Then
                    Me.zivot1.Hide()
                End If
                If HP1 = 1 Then
                    Me.zivot2.Hide()
                End If
                If HP1 = 0 Then
                    Me.zivot3.Hide()
                    Me.konec2 = MsgBox(Msg2, vbYesNo)
                    If konec2 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Ystrela2 = Ystrela2 + 5
            Strela2 = 6
        End If

        REM strela doleva
        If Strela2 = 7 Then
            Me.Kulka2.Width = 10
            Me.Kulka2.Height = 7
            Me.Kulka2.Image = Me.Kulkavlevo2.Image
            Me.Kulka2.Show()
            Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 - 20, Ystrela2 + 10)
            If Me.Kulka2.Location.X < 3 Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 - 20, Ystrela2 + 3)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka2.Location.X > Me.Tank1.Location.X) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 4) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 - 17, Ystrela2 + 2)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
                Me.HP1 = HP1 - 1

                If HP1 = 2 Then
                    Me.zivot1.Hide()
                End If
                If HP1 = 1 Then
                    Me.zivot2.Hide()
                End If
                If HP1 = 0 Then
                    Me.zivot3.Hide()
                    Me.konec2 = MsgBox(Msg2, vbYesNo)
                    If konec2 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
                Xstrela2 = Xstrela2 - 5
                Strela2 = 7
            End If
        End If

        REM strela doprava
        If Strela2 = 8 Then
            Me.Kulka2.Width = 10
            Me.Kulka2.Height = 7
            Me.Kulka2.Image = Me.Kulkavpravo2.Image()
            Me.Kulka2.Show()
            Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 40, Ystrela2 + 9)
            If Me.Kulka2.Location.X > Me.Width - 38 Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 40, Ystrela2 + 2)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
            End If
            REM podminka pro zasahnuti tanku kulkou
            If (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - Me.Kulka2.Width) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 4) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) Then
                Timer3.Stop()
                Me.Kulka2.Hide()
                Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 26, Ystrela2 + 2)
                Me.Vybuch2.Show()
                Vystreleno2 = 0
                Timer4.Start()
                Me.HP1 = HP1 - 1

                If HP1 = 2 Then
                    Me.zivot1.Hide()
                End If
                If HP1 = 1 Then
                    Me.zivot2.Hide()
                End If
                If HP1 = 0 Then
                    Me.zivot3.Hide()
                    Me.konec2 = MsgBox(Msg2, vbYesNo)
                    If konec2 = vbYes Then
                        Application.Restart()
                    Else
                        End
                    End If
                End If
            End If
            Xstrela2 = Xstrela2 + 5
            Strela2 = 8
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        'Konecvystrelu = Konecvystrelu + 1
        'If Konecvystrelu = 2 Then

        Me.Vybuch.Hide()
        Timer2.Stop()

        'Konecvystrelu = 0
        'End If
    End Sub

    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        Konecvystrelu2 = Konecvystrelu2 + 1
        If Konecvystrelu2 = 2 Then
            Me.Vybuch2.Hide()
            Timer4.Stop()
            Konecvystrelu2 = 0
        End If
    End Sub

End Class

Šmakoun
Visual Basic › Tanková hra pomoc s příkazi
13. 3. 2019   #383284

#3 Šmakoun
Ohledně té location 

 Dim X1, Y1, X2, Y2, Smer, Smer2, Xstrela, Ystrela, Strela, Vystreleno, Konecvystrelu As Integer
    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal klavesa As Keys) As Boolean
        X1 = Me.Tank1.Location.X
        Y1 = Me.Tank1.Location.Y
        X2 = Me.Tank2.Location.X
        Y2 = Me.Tank2.Location.Y

        REM Tank1
        If Me.Tank1.Location.Y > 0 Then
            If klavesa = Keys.Up Then
                Me.Tank1.Image = Me.Tanknahoru.Image
                Y1 = Y1 - 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 1
            End If
        End If

        If Me.Tank1.Location.Y < Me.Height - 69 Then
            If klavesa = Keys.Down Then
                Me.Tank1.Image = Me.Tankdolu.Image
                Y1 = Y1 + 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 2
            End If
        End If

        If Me.Tank1.Location.X > 0 Then
            If klavesa = Keys.Left Then
                Me.Tank1.Image = Me.Tankvlevo.Image
                X1 = X1 - 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 3
            End If
        End If

        If Me.Tank1.Location.X < Me.Width - 48 Then
            If klavesa = Keys.Right Then
                Me.Tank1.Image = Me.Tankvpravo.Image
                X1 = X1 + 3
                Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
                Smer = 4
            End If
        End If

        REM proměnná Vystreleno pro zakázání dalšího výstřelu během letu kulky
        If Vystreleno = 0 Then
            If klavesa = Keys.Space Then
                Xstrela = Me.Tank1.Location.X
                Ystrela = Me.Tank1.Location.Y
                Strela = Smer
                Timer1.Start()
                Vystreleno = 1
            End If
        End If


        REM Tank2
        If Me.Tank2.Location.Y > 0 Then
            If klavesa = Keys.W Then
                Me.Tank2.Image = Me.Tank2nahoru.Image
                Y2 = Y2 - 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 5
            End If
        End If

        If Me.Tank2.Location.Y < Me.Height - 69 Then
            If klavesa = Keys.S Then
                Me.Tank2.Image = Me.Tank2dolu.Image
                Y2 = Y2 + 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 6
            End If
        End If

        If Me.Tank2.Location.X > 0 Then
            If klavesa = Keys.A Then
                Me.Tank2.Image = Me.Tank2vlevo.Image
                X2 = X2 - 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 7
            End If
        End If

        If Me.Tank2.Location.X < Me.Width - 48 Then
            If klavesa = Keys.D Then
                Me.Tank2.Image = Me.Tank2vpravo.Image
                X2 = X2 + 3
                Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
                Smer2 = 8
            End If
        End If

        Return MyBase.ProcessCmdKey(msg, klavesa)
    End Function

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Smer = 4
        Me.BackColor = Color.White
        Vystreleno = 0
    End Sub


    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        REM strela nahoru
        If Strela = 1 Then
            Me.Kulka.Image = Me.Kulkanahoru.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 9, Ystrela - 19)
            If Me.Kulka.Location.Y < 3 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela - 19)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            Ystrela = Ystrela - 5
            Strela = 1
        End If

        REM strela dolu
        If Strela = 2 Then
            Me.Kulka.Image = Me.Kulkadolu.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 10, Ystrela + 39)
            If Me.Kulka.Location.Y > Me.Height - 59 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 3, Ystrela + 39)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            Ystrela = Ystrela + 5
            Strela = 2
        End If

        REM strela doleva
        If Strela = 3 Then
            Me.Kulka.Image = Me.Kulkavlevo.Image
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 10)
            If Me.Kulka.Location.X < 3 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 3)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            Xstrela = Xstrela - 5
            Strela = 3
        End If

        REM strela doprava
        If Strela = 4 Then
            Me.Kulka.Image = Me.Kulkavpravo.Image()
            Me.Kulka.Show()
            Me.Kulka.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 9)
            If Me.Kulka.Location.X > Me.Width - 38 Then
                Timer1.Stop()
                Me.Kulka.Hide()
                Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 2)
                Me.Vybuch.Show()
                Vystreleno = 0
                Timer2.Start()
            End If
            Xstrela = Xstrela + 5
            Strela = 4
        End If


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Konecvystrelu = Konecvystrelu + 1
        If Konecvystrelu = 2 Then
            Me.Vybuch.Hide()
            Timer2.Stop()
            Konecvystrelu = 0
        End If
    End Sub
End Class

Šmakoun
Visual Basic › Tanková hra pomoc s příkazi
13. 3. 2019   #383280

#2 peter
Ahoj no mohl bys mě uvést příklad? Mohu přeposlat na e-mail celý soubor aby se lépe orientovalo.

Šmakoun
Visual Basic › Tanková hra pomoc s příkazi
12. 3. 2019   #383269

Zdravím všeci odborníky, mám tady dilema mám docela dlouhý kód. Jedná se o tankovou hru kde jsou dva tanky, výstřeli se mohou zabít. Vše vcelku funguje až na to že nelze hrát oběma tanky zároveň kulka tankem proletí. Uměl by mě někdo pomoc s kodem? Děkuji moc. 

Připojen obrázek.

Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Vybuch = New System.Windows.Forms.PictureBox()
        Me.Kulkavlevo = New System.Windows.Forms.PictureBox()
        Me.Kulkavpravo = New System.Windows.Forms.PictureBox()
        Me.Kulkadolu = New System.Windows.Forms.PictureBox()
        Me.Kulkanahoru = New System.Windows.Forms.PictureBox()
        Me.Kulka = New System.Windows.Forms.PictureBox()
        Me.Tank1 = New System.Windows.Forms.PictureBox()
        Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
        Me.Tankvpravo = New System.Windows.Forms.PictureBox()
        Me.Tankvlevo = New System.Windows.Forms.PictureBox()
        Me.Tankdolu = New System.Windows.Forms.PictureBox()
        Me.Tanknahoru = New System.Windows.Forms.PictureBox()
        Me.Tank2 = New System.Windows.Forms.PictureBox()
        Me.Tank2nahoru = New System.Windows.Forms.PictureBox()
        Me.Tank2dolu = New System.Windows.Forms.PictureBox()
        Me.Tank2vpravo = New System.Windows.Forms.PictureBox()
        Me.Tank2vlevo = New System.Windows.Forms.PictureBox()
        CType(Me.Vybuch, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Kulkavlevo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Kulkavpravo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Kulkadolu, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Kulkanahoru, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Kulka, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tankvpravo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tankvlevo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tankdolu, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tanknahoru, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank2nahoru, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank2dolu, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank2vpravo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tank2vlevo, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Timer1
        '
        Me.Timer1.Interval = 25
        '
        'Vybuch
        '
        Me.Vybuch.Image = Global.Tanky.My.Resources.Resources.vybuch
        Me.Vybuch.Location = New System.Drawing.Point(35, 280)
        Me.Vybuch.Name = "Vybuch"
        Me.Vybuch.Size = New System.Drawing.Size(21, 20)
        Me.Vybuch.TabIndex = 10
        Me.Vybuch.TabStop = False
        Me.Vybuch.Visible = False
        '
        'Kulkavlevo
        '
        Me.Kulkavlevo.Image = Global.Tanky.My.Resources.Resources.Tankkulkavlevo
        Me.Kulkavlevo.Location = New System.Drawing.Point(35, 232)
        Me.Kulkavlevo.Name = "Kulkavlevo"
        Me.Kulkavlevo.Size = New System.Drawing.Size(14, 10)
        Me.Kulkavlevo.TabIndex = 9
        Me.Kulkavlevo.TabStop = False
        Me.Kulkavlevo.Visible = False
        '
        'Kulkavpravo
        '
        Me.Kulkavpravo.Image = Global.Tanky.My.Resources.Resources.Tankkulkavpravo
        Me.Kulkavpravo.Location = New System.Drawing.Point(35, 259)
        Me.Kulkavpravo.Name = "Kulkavpravo"
        Me.Kulkavpravo.Size = New System.Drawing.Size(18, 15)
        Me.Kulkavpravo.TabIndex = 8
        Me.Kulkavpravo.TabStop = False
        Me.Kulkavpravo.Visible = False
        '
        'Kulkadolu
        '
        Me.Kulkadolu.Image = Global.Tanky.My.Resources.Resources.Tankkulkadolu
        Me.Kulkadolu.Location = New System.Drawing.Point(35, 214)
        Me.Kulkadolu.Name = "Kulkadolu"
        Me.Kulkadolu.Size = New System.Drawing.Size(18, 15)
        Me.Kulkadolu.TabIndex = 7
        Me.Kulkadolu.TabStop = False
        Me.Kulkadolu.Visible = False
        '
        'Kulkanahoru
        '
        Me.Kulkanahoru.Image = Global.Tanky.My.Resources.Resources.Tankkulkanahoru
        Me.Kulkanahoru.Location = New System.Drawing.Point(35, 196)
        Me.Kulkanahoru.Name = "Kulkanahoru"
        Me.Kulkanahoru.Size = New System.Drawing.Size(21, 15)
        Me.Kulkanahoru.TabIndex = 6
        Me.Kulkanahoru.TabStop = False
        Me.Kulkanahoru.Visible = False
        '
        'Kulka
        '
        Me.Kulka.Image = Global.Tanky.My.Resources.Resources.Tankkulka
        Me.Kulka.Location = New System.Drawing.Point(35, 306)
        Me.Kulka.Name = "Kulka"
        Me.Kulka.Size = New System.Drawing.Size(21, 20)
        Me.Kulka.TabIndex = 5
        Me.Kulka.TabStop = False
        Me.Kulka.Visible = False
        '
        'Tank1
        '
        Me.Tank1.Image = Global.Tanky.My.Resources.Resources.tank
        Me.Tank1.Location = New System.Drawing.Point(211, 99)
        Me.Tank1.Name = "Tank1"
        Me.Tank1.Size = New System.Drawing.Size(39, 35)
        Me.Tank1.TabIndex = 0
        Me.Tank1.TabStop = False
        '
        'Timer2
        '
        Me.Timer2.Interval = 400
        '
        'Tankvpravo
        '
        Me.Tankvpravo.Image = Global.Tanky.My.Resources.Resources.tankvpravo
        Me.Tankvpravo.Location = New System.Drawing.Point(35, 131)
        Me.Tankvpravo.Name = "Tankvpravo"
        Me.Tankvpravo.Size = New System.Drawing.Size(32, 27)
        Me.Tankvpravo.TabIndex = 11
        Me.Tankvpravo.TabStop = False
        Me.Tankvpravo.Visible = False
        '
        'Tankvlevo
        '
        Me.Tankvlevo.Image = Global.Tanky.My.Resources.Resources.tankvlevo
        Me.Tankvlevo.Location = New System.Drawing.Point(35, 99)
        Me.Tankvlevo.Name = "Tankvlevo"
        Me.Tankvlevo.Size = New System.Drawing.Size(32, 26)
        Me.Tankvlevo.TabIndex = 12
        Me.Tankvlevo.TabStop = False
        Me.Tankvlevo.Visible = False
        '
        'Tankdolu
        '
        Me.Tankdolu.Image = Global.Tanky.My.Resources.Resources.tankdolu
        Me.Tankdolu.Location = New System.Drawing.Point(35, 61)
        Me.Tankdolu.Name = "Tankdolu"
        Me.Tankdolu.Size = New System.Drawing.Size(26, 32)
        Me.Tankdolu.TabIndex = 13
        Me.Tankdolu.TabStop = False
        Me.Tankdolu.Visible = False
        '
        'Tanknahoru
        '
        Me.Tanknahoru.Image = Global.Tanky.My.Resources.Resources.tanknahoru
        Me.Tanknahoru.Location = New System.Drawing.Point(35, 23)
        Me.Tanknahoru.Name = "Tanknahoru"
        Me.Tanknahoru.Size = New System.Drawing.Size(27, 32)
        Me.Tanknahoru.TabIndex = 14
        Me.Tanknahoru.TabStop = False
        Me.Tanknahoru.Visible = False
        '
        'Tank2
        '
        Me.Tank2.Image = Global.Tanky.My.Resources.Resources.tank2
        Me.Tank2.Location = New System.Drawing.Point(553, 359)
        Me.Tank2.Name = "Tank2"
        Me.Tank2.Size = New System.Drawing.Size(39, 35)
        Me.Tank2.TabIndex = 15
        Me.Tank2.TabStop = False
        '
        'Tank2nahoru
        '
        Me.Tank2nahoru.Image = Global.Tanky.My.Resources.Resources.tank2nahoru
        Me.Tank2nahoru.Location = New System.Drawing.Point(740, 115)
        Me.Tank2nahoru.Name = "Tank2nahoru"
        Me.Tank2nahoru.Size = New System.Drawing.Size(27, 32)
        Me.Tank2nahoru.TabIndex = 16
        Me.Tank2nahoru.TabStop = False
        Me.Tank2nahoru.Visible = False
        '
        'Tank2dolu
        '
        Me.Tank2dolu.Image = Global.Tanky.My.Resources.Resources.tank2dolu
        Me.Tank2dolu.Location = New System.Drawing.Point(735, 45)
        Me.Tank2dolu.Name = "Tank2dolu"
        Me.Tank2dolu.Size = New System.Drawing.Size(27, 32)
        Me.Tank2dolu.TabIndex = 17
        Me.Tank2dolu.TabStop = False
        Me.Tank2dolu.Visible = False
        '
        'Tank2vpravo
        '
        Me.Tank2vpravo.Image = Global.Tanky.My.Resources.Resources.tank2vpravo
        Me.Tank2vpravo.Location = New System.Drawing.Point(735, 83)
        Me.Tank2vpravo.Name = "Tank2vpravo"
        Me.Tank2vpravo.Size = New System.Drawing.Size(32, 26)
        Me.Tank2vpravo.TabIndex = 18
        Me.Tank2vpravo.TabStop = False
        Me.Tank2vpravo.Visible = False
        '
        'Tank2vlevo
        '
        Me.Tank2vlevo.Image = Global.Tanky.My.Resources.Resources.tank2vlevo
        Me.Tank2vlevo.Location = New System.Drawing.Point(735, 153)
        Me.Tank2vlevo.Name = "Tank2vlevo"
        Me.Tank2vlevo.Size = New System.Drawing.Size(32, 27)
        Me.Tank2vlevo.TabIndex = 19
        Me.Tank2vlevo.TabStop = False
        Me.Tank2vlevo.Visible = False
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(790, 497)
        Me.Controls.Add(Me.Tank2vlevo)
        Me.Controls.Add(Me.Tank2vpravo)
        Me.Controls.Add(Me.Tank2dolu)
        Me.Controls.Add(Me.Tank2nahoru)
        Me.Controls.Add(Me.Tank2)
        Me.Controls.Add(Me.Tanknahoru)
        Me.Controls.Add(Me.Tankdolu)
        Me.Controls.Add(Me.Tankvlevo)
        Me.Controls.Add(Me.Tankvpravo)
        Me.Controls.Add(Me.Vybuch)
        Me.Controls.Add(Me.Kulkavlevo)
        Me.Controls.Add(Me.Kulkavpravo)
        Me.Controls.Add(Me.Kulkadolu)
        Me.Controls.Add(Me.Kulkanahoru)
        Me.Controls.Add(Me.Kulka)
        Me.Controls.Add(Me.Tank1)
        Me.Name = "Form2"
        Me.Text = "Tanky"
        CType(Me.Vybuch, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Kulkavlevo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Kulkavpravo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Kulkadolu, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Kulkanahoru, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Kulka, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tankvpravo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tankvlevo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tankdolu, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tanknahoru, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank2nahoru, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank2dolu, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank2vpravo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tank2vlevo, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Tank1 As System.Windows.Forms.PictureBox
    Friend WithEvents Kulka As System.Windows.Forms.PictureBox
    Friend WithEvents Kulkanahoru As System.Windows.Forms.PictureBox
    Friend WithEvents Kulkadolu As System.Windows.Forms.PictureBox
    Friend WithEvents Kulkavpravo As System.Windows.Forms.PictureBox
    Friend WithEvents Kulkavlevo As System.Windows.Forms.PictureBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Vybuch As System.Windows.Forms.PictureBox
    Friend WithEvents Timer2 As System.Windows.Forms.Timer
    Friend WithEvents Tankvpravo As System.Windows.Forms.PictureBox
    Friend WithEvents Tankvlevo As System.Windows.Forms.PictureBox
    Friend WithEvents Tankdolu As System.Windows.Forms.PictureBox
    Friend WithEvents Tanknahoru As System.Windows.Forms.PictureBox
    Friend WithEvents Tank2 As System.Windows.Forms.PictureBox
    Friend WithEvents Tank2nahoru As System.Windows.Forms.PictureBox
    Friend WithEvents Tank2dolu As System.Windows.Forms.PictureBox
    Friend WithEvents Tank2vpravo As System.Windows.Forms.PictureBox
    Friend WithEvents Tank2vlevo As System.Windows.Forms.PictureBox
End Class

Kolega
Inzerce › Chci uspět v IT
10. 7. 2015   #203520

Trefa do černého, věta o korporátním kariérismu sedí jako p..el na hrnec.

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý