Thread: need help with a timer

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    221

    need help with a timer

    for a game im making, i need to impliment a timer so that it continously updates on screen, and terminates the program after its done. i am totally baffaled on how to start this.
    PLEASE HELP

    any FAQs or anything.

    also, i need the user to be able to use the computer while the timer is moving, obviously

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    can you use windows.h in a console program?

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by revelation437
    can you use windows.h in a console program?
    Yes.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    ah, it does
    question 2 is
    1000 * 60
    exactly what do those numbers mean?

  6. #6
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    milliseconds * seconds

    1000 = milliseconds

    60 = seconds

    the GetTickCount() function returns miliseconds, so we multiply them by (regular) seconds.

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    one more question
    since this is a loop, it wont actually check the timer until it ends the loop
    the problem with tha is taht, if someone waits in game for input, the timer will never be checked, thus giving him unlimited time

    any way around this?

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    how about

    [code]
    #include <windows.h>
    int main()
    {
    .....code.....
    }
    int thing's to do...code...
    goto repeat;
    {
    .....code.....
    }
    int repeat
    {
    Sleep (60);
    return thing's to do
    }

  9. #9
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    sorry, i really have no idea what you're tryin to say

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by revelation437
    one more question
    since this is a loop, it wont actually check the timer until it ends the loop
    the problem with tha is taht, if someone waits in game for input, the timer will never be checked, thus giving him unlimited time

    any way around this?
    You'd have to write your own input function. This can be done using kbhit() and getch(), though you'll need conio.h which isn't a standard header.
    Code:
    DWORD StartTime = GetTickCount()
    DWORD TimeFrame = 1000 * 60;
    
    while((GetTickCount() - StartTime) < TimeFrame)
    {
       if(kbhit())
       {
          Key = getch();
          AddCharacterToInputBuffer(Key);
       }
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  11. #11
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    anything like that in microsoft
    borland's getch() doesnt work at all in windows 2k (i have 5.01 and cant get the upgrade)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM