Messing with some code, what do you think?

in #fart28 days ago

a simple text-based number guessing game in Python, Here's a basic implementation:

import random

def guess_number():
    print("Welcome to the Number Guessing Game!")
    print("I'm thinking of a number between 1 and 100.")
    secret_number = random.randint(1, 100)
    attempts = 0

    while True:
        guess = input("Take a guess: ")
        try:
            guess = int(guess)
        except ValueError:
            print("Please enter a valid number.")
            continue

        attempts += 1

        if guess < secret_number:
            print("Too low! Try again.")
        elif guess > secret_number:
            print("Too high! Try again.")
        else:
            print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts.")
            break

if __name__ == "__main__":
    guess_number()

This code will randomly generate a number between 1 and 100 and prompt the player to guess the number. After each guess, it will inform the player if the guess was too high or too low. Once the player guesses the correct number, it will print a congratulatory message along with the number of attempts it took.

Now here's a simple text-based Python game where the player needs to escape a room filled with farts:

import time
import random

def escape_room():
    print("Welcome to the Escape Room Fart Edition!")
    print("You find yourself trapped in a room filled with toxic farts.")
    print("You must find the key to unlock the door and escape before you suffocate!")
    print("")

    time.sleep(2)

    # Initialize variables
    key_location = random.randint(1, 3)
    player_location = 1

    # Game loop
    while True:
        print("You're in room", player_location)
        print("You smell something terrible...")

        # Player chooses direction
        while True:
            direction = input("Enter 'L' to go left, 'R' to go right, or 'Q' to quit: ").upper()
            if direction in ['L', 'R', 'Q']:
                break
            else:
                print("Invalid input. Please enter 'L', 'R', or 'Q'.")

        # Quit the game
        if direction == 'Q':
            print("You give up and succumb to the farts. Game over!")
            break

        # Move player
        if direction == 'L':
            player_location -= 1
        elif direction == 'R':
            player_location += 1

        # Check if player has reached the key
        if player_location == key_location:
            print("You found the key!")
            print("You unlock the door and escape from the farty room. Congratulations!")
            break

        # Check if player has reached an invalid location
        if player_location < 1 or player_location > 3:
            print("You stumble into a wall and get lost in the farts. Game over!")
            break

        time.sleep(1)

if __name__ == "__main__":
    escape_room()

In this game, the player starts in a room filled with farts and must navigate through the rooms to find the key and escape through the door. Each time the player moves left or right, they encounter the smell of farts. If the player reaches the key, they win the game. If they run into a wall or decide to quit, they lose.

7gj3j7.jpg

Sort:  

!LOL

Posted using MemeHive

What do a tick and the Eiffel Tower have in common?
They're both Paris sites.

Credit: dyson-the-booper
@epic-fail, I sent you an $LOLZ on behalf of holovision

(2/10)
Farm LOLZ tokens when you Delegate Hive or Hive Tokens.
Click to delegate: 10 - 20 - 50 - 100 HP