Thread obsoleto Snake in VB 2010.net

chana

Nuovo utente
Autore del topic
16 Maggio 2012
1
0
Miglior risposta
0
questo è una parte del mio codice del mio snake,in VB 2010 .net, non riesco a farlo funzionare,nel senso che non gira quando dovrebbe, cioe va solo in una direzione e basta, non capisco dove stia l'errore, ho provato diversi modi e nulla, potreste darmi una mano? :

Private Sub timmov_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timMov.Tick
Dim pt, ptP, pt1, pt2, pt3, pt4 As Point
ptP = pcbPrinc.Location
pt1 = pcbS1.Location
pt2 = pcbS2.Location
pt3 = pcbS3.Location
pt4 = pcbS4.Location
pcbS4.Location = pt3
pcbS3.Location = pt2
pcbS2.Location = pt1
pcbS1.Location = ptP
SLocation(pcbPrinc.Location, Mov_X, Mov_Y)
If pcbPrinc.Location.X >= Me.Size.Width Then
ptP.X = 0
pcbPrinc.Location = ptP
End If
If pcbPrinc.Location.Y >= lnsFine.Y1 Then
ptP.Y = 0
pcbPrinc.Location = ptP
End If
If pcbPrinc.Location.X <= -5 Then
ptP.X = Me.Size.Width
pcbPrinc.Location = ptP
End If
If pcbPrinc.Location.Y <= -5 Then
ptP.Y = lnsFine.Y1 - 20
pcbPrinc.Location = ptP
End If
SLocation(pcbPrinc.Location, Mov_X, Mov_Y)
SLocation(pcbS1.Location, Mov_X, Mov_Y)
SLocation(pcbS2.Location, Mov_X, Mov_Y)
SLocation(pcbS3.Location, Mov_X, Mov_Y)
SLocation(pcbS4.Location, Mov_X, Mov_Y)
pt = pcbS1.Location
pt.X = pcbPrinc.Location.X - 20
pt.Y = pcbPrinc.Location.Y
pcbS1.Location = pt
pt = pcbS2.Location
pt.X = pcbS1.Location.X - 20
pt.Y = pcbS1.Location.Y
pcbS2.Location = pt
pt = pcbS3.Location
pt.X = pcbS2.Location.X - 20
pt.Y = pcbS2.Location.Y
pcbS3.Location = pt
pt = pcbS4.Location
pt.X = pcbS3.Location.X - 20
pt.Y = pcbS3.Location.Y
pcbS4.Location = pt
If (pcbPrinc.Location = pcbS2.Location) Or (pcbPrinc.Location = pcbS3.Location) Or (pcbPrinc.Location = pcbS4.Location) Then
timMov.Enabled = False
MsgBox("Hai Perso")
pcbPrinc.Location = PtPrinc
pcbS1.Location = PtS1
pcbS2.Location = PtS2
pcbS3.Location = PtS3
pcbS4.Location = PtS4
If Int(lblScore.Text) > Int(lblRecord.Text) Then
lblRecord.Text = lblScore.Text
End If
End If
If pcbPrinc.Location = PcbCibo.Location Then
lblScore.Text = Int(lblScore.Text) + 1
Game()
End If
End Sub


Private Sub cmdStrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStrt.Click
cmdPausa.Enabled = True
cmdStrt.Enabled = False
timMov.Enabled = True
End Sub
Private Sub cmdPausa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPausa.Click
cmdStrt.Enabled = True
cmdPausa.Enabled = False
timMov.Enabled = False
pcbPrinc.Location = PtPrinc
pcbS1.Location = PtS1
pcbS2.Location = PtS2
pcbS3.Location = PtS3
pcbS4.Location = PtS4
If Int(lblScore.Text) > Int(lblRecord.Text) Then
lblRecord.Text = lblScore.Text
End If
End Sub


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Then
pcbPrinc.Left = pcbPrinc.Left - 10
End If

If e.KeyCode = Keys.Right Then
pcbPrinc.Left = pcbPrinc.Left + 10
End If

If e.KeyCode = Keys.Up Then
pcbPrinc.Top = pcbPrinc.Top - 10
End If

If e.KeyCode = Keys.Down Then
pcbPrinc.Top = pcbPrinc.Top + 10
End If

End Sub
 
Riferimento: Snake in VB 2010.net

Non gira quando dovrebbe, ossia hai un problema con gli input da tastiera ? o con il movimento ?
Inoltre creare un gioco per quanto semplice utilizzando delle picturebox è un idea alquanto malsana