determine Timer priority

quddusaliquddus

Active member
Joined
Nov 20, 2007
Messages
25
Programming Experience
Beginner
Hi all :),
I basically have the following code: [There's a form called Form1.vb, theres 4 timers called Timer1,Timer2,Timer3,Timer4 on the form, theres a Shockwave Flash Object called ShockPet on the form, theres four buttons: button1 has "Feed" as a caption, button2 has "Play", button3 "Sleep", Buton4 has "Restart"]

It meant to be a virtual pet.

VB.NET:
Public Class Form1
    Dim Age As New Stopwatch
    Dim A As Boolean = False
    Dim ALevel As Integer = 1

    Dim H As Boolean = False
    Dim HLevel As Integer = 0
    Dim Hunger As New Stopwatch
    
    Dim Bored As New Stopwatch
    Dim B As Boolean = False
    Dim BLevel As Integer = 0

    Dim Sleepy As New Stopwatch
    Dim S As Boolean = False
    Dim SLevel As Integer = 0

    Dim CurrentActivity As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShockPet.LoadMovie(0, CurDir() + "/Experiment 1.swf")
        ShockPet.Stop()
        Timer1.Interval = 1000
        Timer2.Interval = 1000
        Timer3.Interval = 1000
        Timer4.Interval = 1000
        Age.Start()
        Hunger.Start()
        Bored.Start()
        Sleepy.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Age
        If Age.Elapsed.TotalSeconds > 1 And Age.Elapsed.TotalSeconds < 2 Then
            ALevel = 1
            A = False
        End If

        If Age.Elapsed.TotalSeconds > 20 And Age.Elapsed.TotalSeconds < 21 Then
            ALevel = 2
            A = False
        End If

        If Age.Elapsed.TotalSeconds > 30 And Age.Elapsed.TotalSeconds < 31 Then
            ALevel = 3
            A = False
        End If

        If Age.Elapsed.TotalSeconds > 40 And Age.Elapsed.TotalSeconds < 41 Then
            ALevel = 4
            A = False
        End If

        If A = False Then
            Select Case ALevel
                Case 1
                    ShockPet.GotoFrame(1)
                    A = True
                Case 2
                    ShockPet.GotoFrame(2)
                    A = True
                Case 3
                    ShockPet.GotoFrame(3)
                    A = True
                Case 4
                    ShockPet.GotoFrame(4)
                    A = True
            End Select
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        HLevel = 0
        H = False
        Hunger.Reset()
        Hunger.Start()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        'Hunger
        If Hunger.Elapsed.TotalSeconds > 1 And Hunger.Elapsed.TotalSeconds < 2 Then
            HLevel = 0
            H = False
        End If

        If Hunger.Elapsed.TotalSeconds > 5 And Hunger.Elapsed.TotalSeconds < 10 Then
            HLevel = 1
            H = False
        End If

        If Hunger.Elapsed.TotalSeconds > 10 And Hunger.Elapsed.TotalSeconds < 15 Then
            HLevel = 2
            H = False
        End If

        If Hunger.Elapsed.TotalSeconds > 15 Then
            HLevel = 3
            H = False
        End If

        If H = False Then
            Select Case HLevel
                Case 0
                    ShockPet.GotoFrame(5)
                    H = True
                Case 1
                    ShockPet.GotoFrame(6)
                    H = True
                Case 2
                    ShockPet.GotoFrame(7)
                    H = True
                Case 3
                    ShockPet.GotoFrame(8)
                    H = True
            End Select
        End If
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick

        'Bored
        If Bored.Elapsed.TotalSeconds > 1 And Bored.Elapsed.TotalSeconds < 2 Then
            BLevel = 0
            B = False
        End If

        If Bored.Elapsed.TotalSeconds > 5 And Bored.Elapsed.TotalSeconds < 10 Then
            BLevel = 1
            B = False
        End If

        If Bored.Elapsed.TotalSeconds > 10 And Bored.Elapsed.TotalSeconds < 15 Then
            BLevel = 2
            B = False
        End If

        If Bored.Elapsed.TotalSeconds > 15 Then
            BLevel = 3
            B = False
        End If

        If B = False Then
            Select Case BLevel
                Case 0
                    ShockPet.GotoFrame(9)
                    B = True
                Case 1
                    ShockPet.GotoFrame(10)
                    B = True
                Case 2
                    ShockPet.GotoFrame(11)
                    B = True
                Case 3
                    ShockPet.GotoFrame(12)
                    B = True
            End Select
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        BLevel = 0
        B = False
        Bored.Reset()
        Bored.Start()
    End Sub
End Class

HLevel =0 means its not hungry. The same goes for bored and sleepy.

As you can see its unfinished.


My problme is: How can i code it so that when its hungry and tells ShockPet to go to a certain frame - it doesnt tell ShockPet that its bored or sleepy?

Please help!!!

Many many thanks for your time. :D

Regards
Q
 
could you upload your project so i can have a look at it?

looking at the code you've posted, the easiest way is to check which frame is loaded in the other timers, then immediately exit sub if its showing 1 of the hungry frames.

but i'm not sure exactly what order you want the frames to run.
 
How can i code it so that when its hungry and tells ShockPet to go to a certain frame - it doesnt tell ShockPet that its bored or sleepy?
Do you only want to show 'hungry' images when Hlevel is greater than 0? (ie hungry time greater than 1 second)
Perhaps better then to have 4 shock controls that display current level for each aggravation so user can see each level and choose which to remedy?
 
Back
Top