Inspiration

Other games

What it does

By gussing image having fun

How we built it

By Python and Python library

Challenges we ran into

Bugs

Accomplishments that we're proud of

we did it

What we learned

Facing challenge

What's next for Image gussing game

import os # Provides functions for interacting with the operating system, like listing files in a directory. import random # Provides functions for generating random numbers.

--- Configuration ---

IMAGE_DIRECTORY = "images" # The folder where i put my image files NUM_ROUNDS = 3 #How many rounds they will play if not os.path.exists(IMAGE_DIRECTORY):     os.makedirs(IMAGE_DIRECTORY)     print(f"Created folder: {IMAGE_DIRECTORY}")     print("⚠️ Please put your images inside this folder before playing!")

--- Game Data (Associate descriptions with filenames)

image_descriptions = {     "bruno.png": "bruno",     "magu.png": "maguire",     "saka.png": "saka",     "rashi": "rashi", }

def load_images(image_dir):     """Loads images with descriptions from the directory."""     image_paths = []     for filename in os.listdir(image_dir):         if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')) and filename in image_descriptions:             image_path = os.path.join(image_dir, filename)             image_paths.append(image_path)     return image_paths

def play_round(image_path):     """Plays a single round of the image guessing game."""     description = image_descriptions[os.path.basename(image_path)] # Get the description from the filename.     print("\nWhat is the image? (Hint: It starts with: " + description[0] + ")") # Show the first letter as a hint

    guess = input("Enter your guess: ") # Get the player's guess

    if guess.lower() == description.lower(): # Compare the guess (in lowercase) to the description (in lowercase)         print("Correct!")         return True # The player won the round     else:         print("Incorrect. The correct answer was: " + description)         return False # The player lost the round

def main():     """Main game loop."""     image_paths = load_images(IMAGE_DIRECTORY) # Load the image file paths     if not image_paths: # Check if any images were loaded         print("No images found. Make sure you have images in the 'images' directory and descriptions.")         return # Exit the game if no images are found

    score = 0 # Keep track of the player's score     for round_num in range(NUM_ROUNDS): # Loop through the number of rounds         print(f"\n--- Round {round_num + 1} ---")         image_path = random.choice(image_paths) # Pick a random image         #image_paths.remove(image_path) #Remove after, to use this you'll need to add it back! Not for beginner         won_round = play_round(image_path) # Play the round

        if won_round:             score += 1 # Increase the score if the player won             print("Current score: " + str(score))         else:             print("Current score: " + str(score))

    # Game Over Message     print("\n--- Game Over! ---")     print("Final Score: " + str(score))

    if score > NUM_ROUNDS / 2: #Checking the score        print("Congratulations, that is a good score!")     else:        print("Better luck next time!")

--- Start the game ---

if name == "main":     main()

Built With

Share this project:

Updates