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

Anonymní profil Šmakoun – Programujte.comAnonymní profil Šmakoun – Programujte.com

 

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

Š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 © 20032019 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý