-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #893 from souvikpramanikgit/add-wordgame
Add Word Games with lives
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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