Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ By now we have 2 numbers (variables), you and computer

### 🎯 [Guess the number](./Python/Guess_the_number/)
- Language: Python

### 🎯 [Dungeon Escape](./Python/Dungeon_escape/)
- Language: Python

### 🎯 [Memory Flip](./Python/Memory_Flip/)
- Language: Python
12 changes: 12 additions & 0 deletions Python/Dungeon_escape/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dungeon Escape

## Description
A console-based maze adventure!
Navigate a 5×5 dungeon using **N/S/E/W** commands to find the exit (`E`) while avoiding traps (`X`).
You start with 3 lives — lose them all, and the dungeon wins!

---

## How to Run
```bash
python dungeon_escape.py
72 changes: 72 additions & 0 deletions Python/Dungeon_escape/dungeon_escape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import random

# Dungeon size
ROWS, COLS = 5, 5

# Symbols
EMPTY, PLAYER, EXIT, TRAP = '.', 'P', 'E', 'X'

def create_dungeon():
dungeon = [[EMPTY for _ in range(COLS)] for _ in range(ROWS)]
exit_row, exit_col = random.randint(0, ROWS-1), random.randint(0, COLS-1)
dungeon[exit_row][exit_col] = EXIT

# Random traps
for _ in range(5):
r, c = random.randint(0, ROWS-1), random.randint(0, COLS-1)
if dungeon[r][c] == EMPTY:
dungeon[r][c] = TRAP

# Place player
while True:
pr, pc = random.randint(0, ROWS-1), random.randint(0, COLS-1)
if dungeon[pr][pc] == EMPTY:
dungeon[pr][pc] = PLAYER
break
return dungeon, pr, pc

def display_dungeon(dungeon):
for row in dungeon:
print(' '.join(row))
print()

def move_player(dungeon, pr, pc, direction):
dungeon[pr][pc] = EMPTY
if direction == 'N': pr -= 1
elif direction == 'S': pr += 1
elif direction == 'E': pc += 1
elif direction == 'W': pc -= 1
pr, pc = max(0, min(ROWS-1, pr)), max(0, min(COLS-1, pc))
cell = dungeon[pr][pc]
dungeon[pr][pc] = PLAYER
return pr, pc, cell

def play():
dungeon, pr, pc = create_dungeon()
lives = 3

print("🏰 Welcome to Dungeon Escape!")
print("Find the exit (E) and avoid traps (X). Move with N/S/E/W.\n")

while True:
display_dungeon(dungeon)
move = input("Move (N/S/E/W): ").upper()
if move not in ['N', 'S', 'E', 'W']:
print("Invalid move. Try again.")
continue

pr, pc, cell = move_player(dungeon, pr, pc, move)

if cell == EXIT:
display_dungeon(dungeon)
print("🎉 You escaped the dungeon! You win!")
break
elif cell == TRAP:
lives -= 1
print(f"💀 You hit a trap! Lives left: {lives}")
if lives == 0:
print("Game Over! You couldn’t escape.")
break

if __name__ == "__main__":
play()
12 changes: 12 additions & 0 deletions Python/Memory_Flip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Memory Flip Game (Python, Tkinter)

## Description
A simple GUI memory game built with **Tkinter**.
Flip two cards at a time to find matching pairs — match all to win!


---

## How to Run
```bash
python memory_flip.py
50 changes: 50 additions & 0 deletions Python/Memory_Flip/memory_flip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import tkinter as tk
import random
from functools import partial

class MemoryGame:
def __init__(self, root):
self.root = root
self.root.title("🧠 Memory Flip Game")
self.cards = list('AABBCCDDEEFF')
random.shuffle(self.cards)
self.buttons = []
self.flipped = []
self.create_board()
self.matched = 0

def create_board(self):
for i in range(4):
row = []
for j in range(3):
btn = tk.Button(self.root, text='❓', width=8, height=4,
command=partial(self.flip_card, i, j))
btn.grid(row=i, column=j, padx=5, pady=5)
row.append(btn)
self.buttons.append(row)

def flip_card(self, i, j):
idx = i * 3 + j
btn = self.buttons[i][j]
if btn['text'] == '❓' and len(self.flipped) < 2:
btn['text'] = self.cards[idx]
self.flipped.append((i, j))
if len(self.flipped) == 2:
self.root.after(800, self.check_match)

def check_match(self):
(i1, j1), (i2, j2) = self.flipped
b1, b2 = self.buttons[i1][j1], self.buttons[i2][j2]
if b1['text'] == b2['text']:
b1['state'] = b2['state'] = 'disabled'
self.matched += 2
if self.matched == len(self.cards):
tk.Label(self.root, text="🎉 You won!", font=('Arial', 14)).grid(row=5, column=0, columnspan=3)
else:
b1['text'] = b2['text'] = '❓'
self.flipped.clear()

if __name__ == "__main__":
root = tk.Tk()
game = MemoryGame(root)
root.mainloop()
Loading