Wednesday, October 20, 2010

Wednesday, October 20th 2010


Public Class Form1

Dim goRight As Boolean
Dim goBottom As Boolean
Dim tickCount As Integer

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblOne.Click

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


tickCount += 1



If lblOne.Left >= TextBox1.Right - lblOne.Width - 4 Then
goRight = False
End If

If lblOne.Left <= TextBox1.Left + 3 Then
goRight = True
End If

If goRight = True Then
lblOne.Left += 5
Else
lblOne.Left -= 5
End If


If lblOne.Top <= TextBox1.Top + 3 Then
goBottom = False
End If

If lblOne.Top >= TextBox1.Bottom - lblOne.Height - 4 Then
goBottom = True
End If




If goBottom = True Then
lblOne.Top -= 5
Else
lblOne.Top += 5
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
goRight = True
goBottom = True

tickCount = 1
lblOne.Text = "O"
lblOne.BackColor = TextBox1.BackColor

TextBox1.Width = Me.ClientRectangle.Width - 7
TextBox1.Left = Me.ClientRectangle.Left + 3
TextBox1.Height = Me.ClientRectangle.Height - 10
TextBox1.Top = Me.ClientRectangle.Top + 5


End Sub
End Class


I added the ability to move another character around


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Right
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X + 5, lblCharacter.Location.Y)
Case Keys.Left
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X - 5, lblCharacter.Location.Y)
Case Keys.Up
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X, lblCharacter.Location.Y - 5)
Case Keys.Down
lblCharacter.Text = "X"
lblCharacter.Location = New Point(lblCharacter.Location.X, lblCharacter.Location.Y + 5)
End Select
End Sub


I also created a quick program that creates a form


Dim playingField As New TextBox
playingField.Width = 300
playingField.Height = 300
playingField.Multiline = True


Me.Controls.Add(playingField)


Here is a better version of the program to create a form



Dim textDisplay As New TextBox()
textDisplay.Location = New Point(ClientRectangle.Left + 7, ClientRectangle.Top + 7)
textDisplay.Size = New Size(200, 200)
textDisplay.Multiline = True
Me.Controls.Add(textDisplay)

No comments: