Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

My Turn - Threading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 12:12 GMT
I havent played much with threading and Im testing stuff out with a little
space invaders game. My Invader class has a StopInvader StartInvader and
Invade subs.

There is a class level variable called Alive of Type Boolean.

On StartInvader I begin a new thread at the address of Invade and inside
this While Alive  . . . . . . .  Do Stuff ( Move etc )   Wend.

Stop invalder simply sets Alive to False.

OK

So the start starts it OK, and it shoots across the screeen, Fine; Stop
Stops the Invade, however, StartInvader only works the first time,

any ideas ? ( Excuse any bad programming as Im only playing )

Public Class Invader

Private invaderImage As Image

Private invaderImageDelete As Image

Private space As Graphics

Private startPoint As Point

Private currentPoint As New Point

Private Enum direction

left

right

End Enum

Private invaderDirection As direction

Private alive As Boolean = True

Private parentForm As Form1

Private invadeThread As Threading.Thread

Public Sub New(ByVal iSpace As Graphics, ByVal refForm As Form1, ByVal
iInvader As String, ByVal iInvaderDelete As String)

space = iSpace

invaderDirection = direction.right

startPoint = New Point(10, 10)

parentForm = refForm

invaderImage = Image.FromFile(iInvader)

invaderImageDelete = Image.FromFile(iInvaderDelete)

End Sub

Public Sub startInvader()

currentPoint.X = startPoint.X

currentPoint.Y = startPoint.Y

parentForm.newGameButton.Enabled = False

parentForm.stopGameButton.Enabled = True

invadeThread = New Threading.Thread(AddressOf invade)

invadeThread.IsBackground = True

invadeThread.Start()

End Sub

Public Sub stopInvader()

parentForm.newGameButton.Enabled = True

parentForm.stopGameButton.Enabled = False

alive = False

End Sub

Private Sub Fire()

End Sub

Private Sub invade()

While alive

If currentPoint.X > space.VisibleClipBounds.Width Then

currentPoint.X = startPoint.X

currentPoint.Y = startPoint.Y

End If

Threading.Thread.CurrentThread.Sleep(20)

space.DrawImage(MyClass.invaderImageDelete, currentPoint)

currentPoint.X += 5

space.DrawImage(MyClass.invaderImage, currentPoint)

End While

End Sub

Signature

OHM ( Terry Burns )   * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
    ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--

scorpion53061 - 19 Oct 2004 12:16 GMT
Instead of "stop" try "sleep".

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:#2qj1xctEHA.3156@TK2MSFTNGP12.phx.gbl:
> I havent played much with threading and Im testing stuff out with a little
>
[quoted text clipped - 117 lines]
>
> End Sub
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:12 GMT
Imran was correct, but thanks for answering

Signature

OHM ( Terry Burns )   * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
    ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--

> Instead of "stop" try "sleep".
>
[quoted text clipped - 122 lines]
>>
>> End Sub
scorpion53061 - 19 Oct 2004 14:23 GMT
I was just guessing. I didn't have time to pull your code part.

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:uS#dfTdtEHA.1088@TK2MSFTNGP12.phx.gbl:
> Imran was correct, but thanks for answering
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 14:55 GMT
No thats fine really, Im happy for any input to my posts.

Cheers - OHM

Signature

OHM ( Terry Burns )   * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
    ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--

>I was just guessing. I didn't have time to pull your code part.
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
> message news:uS#dfTdtEHA.1088@TK2MSFTNGP12.phx.gbl:
>> Imran was correct, but thanks for answering
Imran Koradia - 19 Oct 2004 12:19 GMT
Just a guess - You're setting alive to false when calling StopInvader which
is never being set to true again which is why the second time Invade just
skips the entire while loop. Or did I overlook something :)??

Imran.

>I havent played much with threading and Im testing stuff out with a little
>space invaders game. My Invader class has a StopInvader StartInvader and
[quoted text clipped - 114 lines]
>
> End Sub
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:12 GMT
Bang On - I just didnt see it ( What an idiot I am )

Thanks

Signature

OHM ( Terry Burns )   * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
    ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--

> Just a guess - You're setting alive to false when calling StopInvader
> which is never being set to true again which is why the second time Invade
[quoted text clipped - 122 lines]
>>
>> End Sub
Cor Ligthert - 19 Oct 2004 13:34 GMT
Do we get it when it is ready?

Cor
Imran Koradia - 19 Oct 2004 13:47 GMT
good question Cor :)

> Do we get it when it is ready?
>
> Cor
One Handed Man \( OHM - Terry Burns \) - 19 Oct 2004 13:49 GMT
LOL, for what its worth, yes, i would be happy to post it.

Signature

OHM ( Terry Burns )   * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
    ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--

> good question Cor :)
>
>> Do we get it when it is ready?
>>
>> Cor
Imran Koradia - 19 Oct 2004 13:47 GMT
> Bang On - I just didnt see it ( What an idiot I am )

naah - maybe you just a little break :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.