Jump to content

Project Bunny

- - - - -

  • Please log in to reply
3 replies to this topic

#1
zapdude1234

zapdude1234

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
I am very new to programming but wanted to start my first project after having learned several basics of Visual Basics 2010. The program is very simple. There is a idle picture box with a bunny (that i might have move) and two labels and two buttons. The bunny has two stats, hunger and love. Both are just integers that degrade with a timer. the buttons are used to add points to the two stat (feed and care). I wanted to somehow connect the stats to the clock on my computer so that when i close the program, the numbers are still degrading. any thoughts?

#2
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
When you serialize/save the file when they try to close the program save the current time stamp. When it loads check the new time stamp. Calculate the difference in the two times and then calculate how much the stats should have gone down based on the time difference and then subtract the stat totals from the stats that you saved when they closed out of the program.
Posted Image

#3
zapdude1234

zapdude1234

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Alright thats what i thought. I've been working on a function that would work. I set the timer interval to 1000 so the iHunger variable is lowering by 1 every second.
So far this is what i have:
I have a 'save' button with the following code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        My.Settings.Hour = Hour(Now)

        My.Settings.Minute = Minute(Now)

        My.Settings.Second = Second(Now)

        My.Settings.Hunger = iHunger

    End Sub

I also have a 'Load' button that does such:
 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        iHunger = My.Settings.Hunger - ((Hour(Now) - My.Settings.Hour) * 3600) + ((Minute(Now) - My.Settings.Minute) * 60) + (Second(Now) - My.Settings.Second)

    End Sub

I think there might be an error in the code though cause its giving me weird numbers. Any suggestions?

#4
zapdude1234

zapdude1234

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Never mind, i just got it working. i just set the time difference to a variable then set iHunger = My.Settings.Hunger - time difference




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users