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

In summary, Jason is working on a text-based game where the player enters data to disarm a bomb. The code includes a timer that counts down, and the player must input the digits before the timer reaches zero. However, the code does not include a way to stop the timer if the player is correct.
  • #1
jasonsmith206
10
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
  • #2
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)
 

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

What is the purpose of the Bomb Game Project?

The purpose of the Bomb Game Project is to create an interactive and challenging game that requires players to use their problem-solving skills to enter a 3-digit code and disarm a bomb before time runs out.

How does the game work?

The game will present players with a virtual bomb that is set to explode in a certain amount of time. The player must enter a 3-digit code using a keypad to disarm the bomb. If the code is incorrect or the player takes too long, the bomb will explode and the game will end.

What skills does this game help develop?

This game helps develop critical thinking, problem-solving, and time management skills. It also requires players to stay calm under pressure and think logically to find the correct code.

Is there a specific strategy to use in this game?

While there is no specific strategy, players may benefit from trying different combinations and patterns when entering the code. It is also important to manage time effectively and not panic under pressure.

Can the game be played multiple times?

Yes, the game can be played multiple times. Each game will have a different code and time limit, providing a new challenge for players each time they play.

Similar threads

Back
Top