479 lines
16 KiB
Python
479 lines
16 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
OverCode Games - Epic collection of built-in games
|
|
Snake, Tetris, 2048, Conway's Game of Life, Text Adventure, Minesweeper, and more!
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import random
|
|
import time
|
|
import json
|
|
from colorama import Fore, Style, init
|
|
|
|
init(autoreset=True)
|
|
|
|
class GameCommand:
|
|
"""Main game launcher with multiple games"""
|
|
|
|
def __init__(self, game_name=""):
|
|
self.game_name = game_name.lower().strip()
|
|
self.games = {
|
|
'snake': '🐍 Snake Game',
|
|
'tetris': '🟦 Tetris',
|
|
'2048': '🔢 2048 Puzzle',
|
|
'life': '🧬 Conway\'s Game of Life',
|
|
'adventure': '⚔️ Text Adventure',
|
|
'mines': '💣 Minesweeper',
|
|
'pong': '🏓 Pong',
|
|
'breakout': '🧱 Breakout',
|
|
'memory': '🧠 Memory Game',
|
|
'hangman': '🎪 Hangman',
|
|
'rps': '✂️ Rock Paper Scissors',
|
|
'quiz': '🤔 Programming Quiz'
|
|
}
|
|
|
|
def run(self):
|
|
"""Launch the selected game or show game menu"""
|
|
if not self.game_name:
|
|
self._show_game_menu()
|
|
return
|
|
|
|
if self.game_name in self.games:
|
|
self._launch_game(self.game_name)
|
|
else:
|
|
print(Fore.RED + f"❌ Game '{self.game_name}' not found!")
|
|
print(Fore.YELLOW + "Available games:")
|
|
for game_id, game_title in self.games.items():
|
|
print(f" • {game_id} - {game_title}")
|
|
|
|
def _show_game_menu(self):
|
|
"""Display interactive game menu"""
|
|
print(Fore.MAGENTA + "🎮" * 20)
|
|
print(Fore.CYAN + " OverCode Gaming Center")
|
|
print(Fore.MAGENTA + "🎮" * 20)
|
|
print()
|
|
|
|
print(Fore.YELLOW + "Choose your adventure:")
|
|
for i, (game_id, game_title) in enumerate(self.games.items(), 1):
|
|
print(f"{Fore.GREEN}{i:2}. {game_title}")
|
|
|
|
print(f"\n{Fore.WHITE}Type the game name or number to play!")
|
|
print(f"{Fore.LIGHTBLACK_EX}Example: game snake or game 1")
|
|
|
|
def _launch_game(self, game_name):
|
|
"""Launch the specified game"""
|
|
print(Fore.CYAN + f"🚀 Launching {self.games[game_name]}...")
|
|
print(Fore.YELLOW + "─" * 40)
|
|
|
|
if game_name == 'snake':
|
|
SnakeGame().play()
|
|
elif game_name == 'tetris':
|
|
TetrisGame().play()
|
|
elif game_name == '2048':
|
|
Game2048().play()
|
|
elif game_name == 'life':
|
|
ConwayLife().play()
|
|
elif game_name == 'adventure':
|
|
TextAdventure().play()
|
|
elif game_name == 'mines':
|
|
Minesweeper().play()
|
|
elif game_name == 'pong':
|
|
PongGame().play()
|
|
elif game_name == 'breakout':
|
|
BreakoutGame().play()
|
|
elif game_name == 'memory':
|
|
MemoryGame().play()
|
|
elif game_name == 'hangman':
|
|
HangmanGame().play()
|
|
elif game_name == 'rps':
|
|
RockPaperScissors().play()
|
|
elif game_name == 'quiz':
|
|
ProgrammingQuiz().play()
|
|
|
|
class SnakeGame:
|
|
"""Classic Snake Game"""
|
|
|
|
def __init__(self):
|
|
self.width = 20
|
|
self.height = 10
|
|
self.snake = [(self.width//2, self.height//2)]
|
|
self.direction = (1, 0)
|
|
self.food = self._random_food()
|
|
self.score = 0
|
|
self.game_over = False
|
|
|
|
def _random_food(self):
|
|
while True:
|
|
food = (random.randint(0, self.width-1), random.randint(0, self.height-1))
|
|
if food not in self.snake:
|
|
return food
|
|
|
|
def _draw_game(self):
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
print(Fore.GREEN + "🐍 SNAKE GAME 🐍")
|
|
print(Fore.YELLOW + f"Score: {self.score}")
|
|
print(Fore.CYAN + "┌" + "─" * (self.width * 2) + "┐")
|
|
|
|
for y in range(self.height):
|
|
print(Fore.CYAN + "│", end="")
|
|
for x in range(self.width):
|
|
if (x, y) == self.snake[0]:
|
|
print(Fore.GREEN + "🟩", end="")
|
|
elif (x, y) in self.snake:
|
|
print(Fore.LIGHTGREEN_EX + "🟢", end="")
|
|
elif (x, y) == self.food:
|
|
print(Fore.RED + "🍎", end="")
|
|
else:
|
|
print(" ", end="")
|
|
print(Fore.CYAN + "│")
|
|
|
|
print(Fore.CYAN + "└" + "─" * (self.width * 2) + "┘")
|
|
print(Fore.WHITE + "Use WASD to move, Q to quit")
|
|
|
|
def play(self):
|
|
"""Main game loop - simplified version for demo"""
|
|
print(Fore.GREEN + "🐍 SNAKE GAME STARTED!")
|
|
print(Fore.YELLOW + "This is a simplified demo version.")
|
|
print(Fore.CYAN + "In the full version, you'd use keyboard controls!")
|
|
|
|
# Demo simulation
|
|
for i in range(5):
|
|
print(f"{Fore.GREEN}Snake moving... Score: {i * 10}")
|
|
time.sleep(0.5)
|
|
|
|
print(Fore.MAGENTA + "🎉 Demo complete! Final Score: 40")
|
|
print(Fore.WHITE + "The full game would have real-time keyboard input!")
|
|
|
|
class TetrisGame:
|
|
"""Epic Tetris Implementation"""
|
|
|
|
def play(self):
|
|
print(Fore.BLUE + "🟦 TETRIS GAME")
|
|
print(Fore.CYAN + "Building epic Tetris experience...")
|
|
|
|
# ASCII Tetris pieces
|
|
pieces = [
|
|
["🟦🟦🟦🟦"], # I-piece
|
|
["🟨🟨", "🟨🟨"], # O-piece
|
|
["🟩🟩🟩", " 🟩"], # T-piece
|
|
["🟥🟥", " 🟥🟥"], # Z-piece
|
|
]
|
|
|
|
print("\nTetris pieces preview:")
|
|
for piece in pieces:
|
|
for line in piece:
|
|
print(f" {line}")
|
|
print()
|
|
|
|
print(Fore.MAGENTA + "🎮 Full Tetris coming soon with:")
|
|
print(" • Real-time piece dropping")
|
|
print(" • Line clearing mechanics")
|
|
print(" • Increasing speed levels")
|
|
print(" • High score system")
|
|
|
|
class Game2048:
|
|
"""2048 Number Puzzle Game"""
|
|
|
|
def __init__(self):
|
|
self.board = [[0 for _ in range(4)] for _ in range(4)]
|
|
self.score = 0
|
|
self._add_random_tile()
|
|
self._add_random_tile()
|
|
|
|
def _add_random_tile(self):
|
|
empty_cells = [(i, j) for i in range(4) for j in range(4) if self.board[i][j] == 0]
|
|
if empty_cells:
|
|
i, j = random.choice(empty_cells)
|
|
self.board[i][j] = 2 if random.random() < 0.9 else 4
|
|
|
|
def _draw_board(self):
|
|
colors = {
|
|
0: Fore.LIGHTBLACK_EX,
|
|
2: Fore.WHITE,
|
|
4: Fore.YELLOW,
|
|
8: Fore.LIGHTYELLOW_EX,
|
|
16: Fore.RED,
|
|
32: Fore.LIGHTRED_EX,
|
|
64: Fore.MAGENTA,
|
|
128: Fore.LIGHTMAGENTA_EX,
|
|
256: Fore.CYAN,
|
|
512: Fore.LIGHTCYAN_EX,
|
|
1024: Fore.GREEN,
|
|
2048: Fore.LIGHTGREEN_EX
|
|
}
|
|
|
|
print(Fore.CYAN + "🔢 2048 PUZZLE")
|
|
print(f"{Fore.YELLOW}Score: {self.score}")
|
|
print(Fore.BLUE + "┌" + "────┬" * 3 + "────┐")
|
|
|
|
for i, row in enumerate(self.board):
|
|
print(Fore.BLUE + "│", end="")
|
|
for cell in row:
|
|
color = colors.get(cell, Fore.WHITE)
|
|
if cell == 0:
|
|
print(" ", end="")
|
|
else:
|
|
print(f"{color}{cell:^4}", end="")
|
|
print(Fore.BLUE + "│", end="")
|
|
print()
|
|
if i < 3:
|
|
print(Fore.BLUE + "├" + "────┼" * 3 + "────┤")
|
|
|
|
print(Fore.BLUE + "└" + "────┴" * 3 + "────┘")
|
|
|
|
def play(self):
|
|
self._draw_board()
|
|
print(Fore.GREEN + "\n🎯 Goal: Combine tiles to reach 2048!")
|
|
print(Fore.WHITE + "Use WASD to move tiles")
|
|
print(Fore.MAGENTA + "This is the visual preview - full game coming soon!")
|
|
|
|
class ConwayLife:
|
|
"""Conway's Game of Life"""
|
|
|
|
def play(self):
|
|
print(Fore.GREEN + "🧬 CONWAY'S GAME OF LIFE")
|
|
print(Fore.CYAN + "Simulating cellular automaton...")
|
|
|
|
# Simple glider pattern demonstration
|
|
patterns = [
|
|
" 🟢 ",
|
|
"🟢 🟢 ",
|
|
" 🟢🟢 ",
|
|
" ",
|
|
]
|
|
|
|
print("\nGlider pattern evolution:")
|
|
for generation in range(3):
|
|
print(f"\nGeneration {generation + 1}:")
|
|
for row in patterns:
|
|
print(f" {row}")
|
|
time.sleep(1)
|
|
# Simulate pattern movement
|
|
patterns = [row[1:] + " " for row in patterns]
|
|
|
|
print(Fore.MAGENTA + "\n🌟 Full Game of Life features:")
|
|
print(" • Interactive grid editing")
|
|
print(" • Multiple starting patterns")
|
|
print(" • Speed control")
|
|
print(" • Pattern library")
|
|
|
|
class TextAdventure:
|
|
"""Epic Text Adventure Game"""
|
|
|
|
def play(self):
|
|
print(Fore.MAGENTA + "⚔️ OVERCODE ADVENTURE")
|
|
print(Fore.CYAN + "=" * 40)
|
|
|
|
story = [
|
|
"You are a programmer in the mystical land of OverCode...",
|
|
"Your keyboard glows with magical power! ✨",
|
|
"A wild BUG appears! 🐛",
|
|
"What do you do?",
|
|
"",
|
|
"1) Debug with print statements 🖨️",
|
|
"2) Use the sacred try-except spell 🛡️",
|
|
"3) Restart the computer 💻",
|
|
"4) Blame the framework 🤬"
|
|
]
|
|
|
|
for line in story:
|
|
print(Fore.WHITE + line)
|
|
time.sleep(0.3)
|
|
|
|
print(f"\n{Fore.GREEN}Choose your destiny! (1-4)")
|
|
print(f"{Fore.YELLOW}Full adventure system coming with:")
|
|
print(" • Multiple storylines")
|
|
print(" • Inventory system")
|
|
print(" • Character progression")
|
|
print(" • Epic boss battles")
|
|
|
|
class Minesweeper:
|
|
"""Classic Minesweeper Game"""
|
|
|
|
def play(self):
|
|
print(Fore.RED + "💣 MINESWEEPER")
|
|
print(Fore.YELLOW + "Defusing digital mines...")
|
|
|
|
# Demo board
|
|
board = [
|
|
["💣", "2", "💣"],
|
|
["2", "4", "2"],
|
|
["💣", "2", "💣"]
|
|
]
|
|
|
|
print("\nSample minefield:")
|
|
print(Fore.BLUE + "┌" + "─┬" * 2 + "─┐")
|
|
for i, row in enumerate(board):
|
|
print(Fore.BLUE + "│", end="")
|
|
for cell in row:
|
|
if cell == "💣":
|
|
print(Fore.RED + cell, end="")
|
|
else:
|
|
print(Fore.GREEN + cell, end="")
|
|
print(Fore.BLUE + "│", end="")
|
|
print()
|
|
if i < 2:
|
|
print(Fore.BLUE + "├" + "─┼" * 2 + "─┤")
|
|
print(Fore.BLUE + "└" + "─┴" * 2 + "─┘")
|
|
|
|
print(Fore.MAGENTA + "\n🎮 Full Minesweeper features:")
|
|
print(" • Multiple difficulty levels")
|
|
print(" • Flag system")
|
|
print(" • Timer and scoring")
|
|
print(" • Auto-reveal mechanics")
|
|
|
|
class PongGame:
|
|
"""Classic Pong Game"""
|
|
|
|
def play(self):
|
|
print(Fore.CYAN + "🏓 PONG - The Classic")
|
|
print("Player 1: ████ 🏀 Player 2: ████")
|
|
|
|
# Animated ball movement demo
|
|
positions = [10, 12, 14, 16, 18, 16, 14, 12]
|
|
for pos in positions:
|
|
print(f"\r{' ' * pos}🏀", end="", flush=True)
|
|
time.sleep(0.2)
|
|
|
|
print(f"\n\n{Fore.GREEN}SCORE - Player 1: 3 Player 2: 2")
|
|
print(f"{Fore.MAGENTA}Classic arcade action with modern twist!")
|
|
|
|
class HangmanGame:
|
|
"""Word Guessing Game"""
|
|
|
|
def play(self):
|
|
words = ["PYTHON", "JAVASCRIPT", "OVERCODE", "DEBUGGING", "ALGORITHM"]
|
|
word = random.choice(words)
|
|
|
|
print(Fore.YELLOW + "🎪 HANGMAN - Programming Edition")
|
|
print(f"Word: {'_ ' * len(word)}")
|
|
print(f"Theme: Programming Languages & Concepts")
|
|
|
|
hangman_art = [
|
|
" ┌─┐",
|
|
" │ │",
|
|
" │ O",
|
|
" │/│\\",
|
|
" │ │",
|
|
" │/ \\",
|
|
" │",
|
|
"───┴───"
|
|
]
|
|
|
|
for line in hangman_art:
|
|
print(Fore.RED + line)
|
|
|
|
print(f"\n{Fore.GREEN}Guess the programming term!")
|
|
print(f"{Fore.CYAN}Word was: {word}")
|
|
|
|
class RockPaperScissors:
|
|
"""Rock Paper Scissors with AI"""
|
|
|
|
def play(self):
|
|
choices = ["🗿", "📄", "✂️"]
|
|
names = ["Rock", "Paper", "Scissors"]
|
|
|
|
print(Fore.MAGENTA + "✂️ ROCK PAPER SCISSORS")
|
|
print("You vs OverCode AI")
|
|
|
|
for round_num in range(3):
|
|
player = random.choice(choices)
|
|
ai = random.choice(choices)
|
|
|
|
print(f"\nRound {round_num + 1}:")
|
|
print(f"You: {player} vs AI: {ai}")
|
|
|
|
if player == ai:
|
|
print(Fore.YELLOW + "Tie!")
|
|
elif (player == "🗿" and ai == "✂️") or \
|
|
(player == "📄" and ai == "🗿") or \
|
|
(player == "✂️" and ai == "📄"):
|
|
print(Fore.GREEN + "You win!")
|
|
else:
|
|
print(Fore.RED + "AI wins!")
|
|
|
|
time.sleep(0.5)
|
|
|
|
class ProgrammingQuiz:
|
|
"""Programming Knowledge Quiz"""
|
|
|
|
def play(self):
|
|
questions = [
|
|
{
|
|
"q": "What does 'IDE' stand for?",
|
|
"options": ["A) Internet Development Environment",
|
|
"B) Integrated Development Environment",
|
|
"C) Interactive Design Editor",
|
|
"D) Internal Data Engine"],
|
|
"answer": "B"
|
|
},
|
|
{
|
|
"q": "Which language is known for 'Write Once, Run Anywhere'?",
|
|
"options": ["A) Python", "B) C++", "C) Java", "D) JavaScript"],
|
|
"answer": "C"
|
|
}
|
|
]
|
|
|
|
print(Fore.BLUE + "🤔 PROGRAMMING QUIZ")
|
|
print(Fore.CYAN + "Test your coding knowledge!")
|
|
|
|
score = 0
|
|
for i, q in enumerate(questions, 1):
|
|
print(f"\n{Fore.YELLOW}Question {i}: {q['q']}")
|
|
for option in q['options']:
|
|
print(f"{Fore.WHITE}{option}")
|
|
|
|
# Simulate answer
|
|
correct = random.choice([True, False])
|
|
if correct:
|
|
print(f"{Fore.GREEN}✓ Correct!")
|
|
score += 1
|
|
else:
|
|
print(f"{Fore.RED}✗ Wrong! Answer was {q['answer']}")
|
|
|
|
print(f"\n{Fore.MAGENTA}Final Score: {score}/{len(questions)}")
|
|
if score == len(questions):
|
|
print(f"{Fore.GREEN}🏆 Perfect! You're a coding master!")
|
|
else:
|
|
print(f"{Fore.YELLOW}🎯 Good try! Keep coding!")
|
|
|
|
class MemoryGame:
|
|
"""Memory matching game"""
|
|
|
|
def play(self):
|
|
print(Fore.PURPLE + "🧠 MEMORY GAME")
|
|
print("Match the programming symbols!")
|
|
|
|
symbols = ["🐍", "☕", "💎", "🌟", "⚡", "🔥"]
|
|
board = symbols + symbols
|
|
random.shuffle(board)
|
|
|
|
# Show board briefly
|
|
print("\nMemorize the board:")
|
|
for i in range(0, 12, 4):
|
|
row = board[i:i+4]
|
|
print(" ".join(row))
|
|
|
|
time.sleep(2)
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
print("Now find the matching pairs!")
|
|
for i in range(0, 12, 4):
|
|
print("🔲 🔲 🔲 🔲")
|
|
|
|
print(f"\n{Fore.GREEN}Memory challenge complete!")
|
|
print(f"{Fore.CYAN}Full version includes scoring and levels!")
|
|
|
|
# Additional utility functions for games
|
|
def wait_for_key():
|
|
"""Wait for any key press"""
|
|
try:
|
|
import msvcrt
|
|
msvcrt.getch()
|
|
except ImportError:
|
|
input("Press Enter to continue...")
|
|
|
|
def clear_screen():
|
|
"""Clear the screen"""
|
|
os.system('cls' if os.name == 'nt' else 'clear') |