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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
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