Skip to content

Commit

Permalink
Merge pull request #893 from souvikpramanikgit/add-wordgame
Browse files Browse the repository at this point in the history
Add Word Games with lives
  • Loading branch information
UTSAVS26 authored Oct 28, 2024
2 parents 8b47841 + 2d215d2 commit 7a3b992
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Game_Development/Word Games with lives/Readme.md
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!
37 changes: 37 additions & 0 deletions Game_Development/Word Games with lives/main.py
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)
2 changes: 2 additions & 0 deletions Project-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7a3b992

Please sign in to comment.