Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:04:39+00:00 2026-06-17T14:04:39+00:00

I would like to make engine for my console application that will count the

  • 0

I would like to make “engine” for my console application that will count the time passed and force the application to do time-based event when certain amount of time has passed. I think about creating a simple text-based strategy game for education purposes (not for homework, just for me).

I tried to create the engine but I didn’t go too far. I do not know how can I apply time-based events break currently pending action in application etc, first here is how I made it:

#include <stdio.h>
#include <conio.h>
#include <Windows.h>
void _sleep(int t);
int main()
{
int seconds_passed = 0; //counts how much time passed since application started
while(1)
{
    //if(seconds_passed == 100) ... time based action
_sleep(1000);
printf("test");
seconds_passed += 1;
}

return 0;
}


void _sleep(int t) 
{ 
    int i;
    for (i = 0; i < (t/100); i++) 
    { 
        Sleep(100); 
    if (kbhit()!= 0)
        {
            getch();
            break; 
    }
    }
}

I tried to make function similar to Sleep() from windows.h, but with ability to break the delay when key is pressed (I don’t know if im going the correct way) – in loop it will start “time passing”, but I want it to be independent of the rest of the code, so it will work silently and take control over action in rest of the code. I need help in any of following things:

-using keyboard to break _sleep() function shouldn’t automatically increase amount of “seconds passed”

-how to make timer independent of action happening in the code? I thought about creating something that could break the whole while(1) loop every second (probably it could be my modified _sleep function), increase counter and go back to the code part where it broke (it would abuse scanf() actions in application but it isnt a problem for now)

-I heard about select() function that maybe could be useful here, anybody has any experience with it and can tell me more?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:04:40+00:00Added an answer on June 17, 2026 at 2:04 pm

    Don’t know if this is a usable answer but when I built a rudimetary game I made it multi threaded in this way:

    1. The event thread would push a message onto a thread safe message
      queue when the user does something.
    2. The “game” thread reads the message queue, processes data, renders the output onto
      the screen and then sleeps for a certain amount of time.

    In this way the event thread could remain blocked until user input occurred while game logic and input/output was done in a simple synchronized way.
    Windows has a threading library you can use (although I haven”t used that one yet as I always use boost threads or posix threads on linux.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make some request-wide data available in my app engine application.
I would like to make a function that takes in a list of integers
Here is my pool game engine done in Box2dFlash. I would like to make
I'm developer of Robocode engine. We would like to make Robocode multilingual and Scala
I would like to add some scripting support to a Silverlight 4 application that
I would like to build an admin section into my App Engine app that
I would like make a script using PHP (probably need JS) to send POST
I would like make an extension method for the generic class A which takes
I would like to make sure my classes are robust - even if they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.