GAME RẮN Đối tượng hình tròn tượng trưng cho đầu rắn, ta gọi dau1 Điều kiện làm cho dau1 di chuyển theo hướng left, right, up, down Với yêu cầu sau di chuyển right, left, up, down giới hạn hình xuất left, right, down, up di chuyển đổi hướng CODE Public Class Form1 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.Up tmup.Enabled = True tmleft.Enabled = False tmright.Enabled = False tmdown.Enabled = False Case Keys.Down tmdown.Enabled = True tmup.Enabled = False tmleft.Enabled = False tmright.Enabled = False Case Keys.Right tmright.Enabled = True tmleft.Enabled = False tmup.Enabled = False tmdown.Enabled = False Case Keys.Left tmleft.Enabled = True tmright.Enabled = False tmup.Enabled = False tmdown.Enabled = False End Select End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub tmright_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmright.Tick dau1.Visible = True If dau1.Visible = True Then dau1.Left += 10 End If If dau1.Left + dau1.Width > Me.Width Then dau1.Visible = True dau1.Left = Me.Width - 1400 End If End Sub Private Sub tmleft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmleft.Tick dau1.Visible = True If dau1.Visible = True Then dau1.Left -= 10 End If If dau1.Left + dau1.Width < Then dau1.Left = Me.Width End If End Sub Private Sub tmup_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmup.Tick dau1.Visible = True If dau1.Visible = True Then dau1.Top -= 10 End If If dau1.Top + dau1.Width < Then dau1.Visible = True dau1.Top = Me.Width - 700 End If End Sub Private Sub tmdown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmdown.Tick dau1.Visible = True If dau1.Visible = True Then dau1.Top += 10 End If If dau1.Top + dau1.Width + 600 > Me.Width Then dau1.Visible = True dau1.Top = Me.Top End If End Sub End Class