MHB Bomb Game Project: Enter 3-Digit Code to Disarm Before Time Runs Out

  • Thread starter Thread starter jasonsmith206
  • Start date Start date
  • Tags Tags
    Bomb Game Project
AI Thread Summary
The discussion revolves around creating a text-based game where a player must input a three-digit code to disarm a bomb within a 60-second countdown. The main challenge is implementing a countdown timer that runs concurrently with user input, allowing the game to detect if the player enters the correct code before time runs out. Suggestions include using functions like kbhit and getch for non-blocking input, or employing threading to manage the timer independently of user input. The current implementation using scanf is limited, as it waits for user input and does not allow for simultaneous countdown. The conversation emphasizes the need for alternative methods to achieve the desired functionality in the game.
jasonsmith206
Messages
10
Reaction score
0
Hey everyone!

This is my own personal project that I'm trying to get right but i ran into a bit of a problem.

Here's the idea:

I want to make a text based game where the player inputs data such as choices or numbers reflected what's asked of them from the program. The below program is "suppose to" be were a player trips a bomb and it counts down from 60 to 0 and the player has that many seconds to input a 3 digit code before the timer reaches zero.

My question is how can i get it to count down and still get the user to scanf their input and then stop the timer if they're right

This code is part of a bigger project so let's just say for sake of argument the player already knows the digits to disarm the bomb so

armNum1=1;
armNum2=2;
armNum3=3;
Code:
void RoomTwo(void){

int Bcounter=60;
int playerNum1,playerNum2,playerNum3;
int armNum,armNum2,armNum3;

printf("-----------------------------------------------------------------\n\n");
printf(">>Oh no you tripped a bomb!\n\n");
printf(">>A small screen reads \"You have 60 seconds to enter a three digit code to disarm\"\n");

printf("Hurry, enter the numbers");

do{

    while(Bcounter!=0){
    printf("\b\b%d", Bcounter);
        Bcounter--;
        Sleep(1000);
    }printf("\n BOOM!");
YourDead();

}while(playerNum1!=armNum&&playerNum2!=armNum2&&playerNum3!=armNum3);
    

printf("Phew! that was close!");return 0;

thank you for any help or suggestions to make this better!
 
Technology news on Phys.org
jasonsmith206 said:
Hey everyone!

This is my own personal project that I'm trying to get right but i ran into a bit of a problem.

Here's the idea:

I want to make a text based game where the player inputs data such as choices or numbers reflected what's asked of them from the program. The below program is "suppose to" be were a player trips a bomb and it counts down from 60 to 0 and the player has that many seconds to input a 3 digit code before the timer reaches zero.

My question is how can i get it to count down and still get the user to scanf their input and then stop the timer if they're right

This code is part of a bigger project so let's just say for sake of argument the player already knows the digits to disarm the bomb so

armNum1=1;
armNum2=2;
armNum3=3;
Code:
void RoomTwo(void){

int Bcounter=60;
int playerNum1,playerNum2,playerNum3;
int armNum,armNum2,armNum3;

printf("-----------------------------------------------------------------\n\n");
printf(">>Oh no you tripped a bomb!\n\n");
printf(">>A small screen reads \"You have 60 seconds to enter a three digit code to disarm\"\n");

printf("Hurry, enter the numbers");

do{

    while(Bcounter!=0){
    printf("\b\b%d", Bcounter);
        Bcounter--;
        Sleep(1000);
    }printf("\n BOOM!");
YourDead();

}while(playerNum1!=armNum&&playerNum2!=armNum2&&playerNum3!=armNum3);
    

printf("Phew! that was close!");return 0;

thank you for any help or suggestions to make this better!

Hi Jason!;)

scanf does not return until we press Enter.
So we cannot trigger the bomb in the meantime.
Best we can do with scanf is to get the time before and after and see if the user was too late.

Alternatively we can use extended functions, like kbhit and getch to read keys only if the user pressed one. Or we might introduce threads to check time independently from scanf. It depends a bit on what is available to you, and how far you want to go. (Thinking)
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top