diff --git a/Game_Development/Word Games with lives/Readme.md b/Game_Development/Word Games with lives/Readme.md new file mode 100644 index 0000000000..c0ca7bc842 --- /dev/null +++ b/Game_Development/Word Games with lives/Readme.md @@ -0,0 +1,49 @@ +# Word Games with Lives 🎮 + +## 🎯 Objective + +This **Word Game** is a fun and challenging word guessing game created using Python. In this game, you try to guess a secret word one letter at a time or by guessing the whole word. You have a limited number of lives, represented by hearts, and each incorrect guess costs you a life. The goal is to guess the word before you run out of lives! + +--- + +**Prerequisite**: Install `Python` + + +Before running the code, make sure you have Python installed on your system. + + +## 🚀 How to Play: + +1. The game selects a random secret word from a predefined list. +2. You will be given a clue, with each letter of the word represented by a `?`. +3. You can either: + - **Guess one letter** at a time. + - **Guess the whole word**. +4. Each correct guess reveals the corresponding letter(s) in the secret word. +5. Each incorrect guess results in losing one of your lives (represented by ♥). +6. The game ends when you either: + - **Guess the word correctly** and win. + - **Run out of lives** and lose. +7. Enjoy the challenge! + +--- + + +## 📝 Features: + +- **Lives System**: You start with 3 lives, and each incorrect guess removes one life. +- **Clue System**: Clue is displayed as `?` to show how many letters the word contains. +- **Simple Controls**: Just input your guesses either as a letter or the whole word. +- **Random Word Selection**: Each time you play, the game selects a random word to guess. + + +--- + +## 💻 Running the Game: + +1. **Download or clone** the game code to your local machine. +2. **Run the game** using the command: + ```bash + python main.py + ``` +3.Start guessing letters or the whole word and try to win before you lose all your lives! diff --git a/Game_Development/Word Games with lives/main.py b/Game_Development/Word Games with lives/main.py new file mode 100644 index 0000000000..ea8165106f --- /dev/null +++ b/Game_Development/Word Games with lives/main.py @@ -0,0 +1,37 @@ +import random +lives = 3 + +words = ['pizza', 'fairy', 'teeth', 'shirt', 'otter', 'plane'] +secret_word = random.choice(words) + +clue = list('?????') +heart_symbol = u'\u2764' + +guessed_word_correctly = False + +def update_clue(guessed_letter, secret_word, clue): + index = 0 + while index < len(secret_word): + if guessed_letter == secret_word[index]: + clue[index] = guessed_letter + index = index + 1 + +while lives > 0: + print(clue) + print('Lives left: ' + heart_symbol * lives) + guess = input('Guess a letter or the whole word: ') + + if guess == secret_word: + guessed_word_correctly = True + break + + if guess in secret_word: + update_clue(guess, secret_word, clue) + else: + print('Incorrect. You lose a life') + lives = lives - 1 + +if guessed_word_correctly: + print('You won! The secret word was ' + secret_word) +else: + print('You lost! The secret word was ' + secret_word) diff --git a/Project-Structure.md b/Project-Structure.md index 4817bb05c8..40b4d54aa2 100644 --- a/Project-Structure.md +++ b/Project-Structure.md @@ -533,6 +533,8 @@ * [Turtle Collection Game](Game_Development/Turtle%20Collection%20Game/Turtle%20Collection%20Game.py) * Visual Novel Code * [Novel](Game_Development/Visual_novel%20_code/Novel.py) + * Word Games With Lives + * [Main](Game_Development/Word%20Games%20with%20lives/main.py) * Word Ladder Puzzle Game * [Main](Game_Development/Word%20Ladder%20Puzzle%20Game/main.py)