Created
April 5, 2024 00:32
-
-
Save sestok/c13465cd56a5194c8b53fe43bbfe6fad to your computer and use it in GitHub Desktop.
Guess the number or the man will be shot in your terminal!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from colorama import Fore, Style, init | |
init() # Initializes colorama | |
def draw_scenario(distance, attempts_left): | |
if attempts_left == 0: | |
print(Fore.RED + "\n💥 BANG! The man was shot." + Style.RESET_ALL) | |
else: | |
print("\nTwo men stand facing each other.") | |
print("🔫" + " " * distance + "🕴️") | |
print(f"{' ' * (distance + 1)}🚶") | |
print(f"Attempts left: {attempts_left}") | |
print("Guess correctly to save the man!") | |
def guess_the_number(): | |
number_to_guess = random.randint(1, 10) # difficulty range | |
attempts = 5 | |
distance = 10 # Initial distance between the two guys | |
print("Welcome to the Guess the Number Game!") | |
print("A man is being threatened, guess the number to save him.") | |
print("I'm thinking of a number between 1 and 10.") | |
while attempts > 0: | |
draw_scenario(distance, attempts) | |
user_guess = int(input("Make a guess: ")) | |
attempts -= 1 | |
if user_guess == number_to_guess: | |
print(Fore.GREEN + "Congratulations! You've guessed the number and saved the man." + Style.RESET_ALL) | |
break | |
else: | |
if attempts == 0: | |
draw_scenario(distance, attempts) | |
break | |
print(Fore.YELLOW + "Incorrect. The situation gets more tense." + Style.RESET_ALL) | |
distance -= 2 | |
if distance < 0: | |
distance = 0 | |
if __name__ == "__main__": | |
guess_the_number() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment