Created
July 15, 2024 17:42
-
-
Save TheLustriVA/a5d26026a03f732a0125f40d85e908fd to your computer and use it in GitHub Desktop.
Feathers game prototype
This file contains hidden or 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
import random | |
from rich.console import Console | |
from rich.panel import Panel | |
from rich.progress import Progress | |
from rich.table import Table | |
from time import sleep | |
console = Console() | |
class Feather: | |
def __init__(self, type, peak_turn): | |
self.type = type | |
self.peak_turn = peak_turn | |
def sneeze_chance(self, current_turn): | |
base_chance = 50 | |
distance_from_peak = abs(current_turn - self.peak_turn) | |
return base_chance - (distance_from_peak * 5) | |
def create_feathers(): | |
feather_types = ["Duck", "Pigeon", "Seagull", "Peacock", "Ostrich", "Eagle", "Owl", "Parrot", "Chicken", "Swan"] | |
return [Feather(f, i) for i, f in enumerate(feather_types, 1)] | |
def display_feathers(feathers, current_turn): | |
table = Table(title=f"Feathers (Turn {current_turn})") | |
table.add_column("Number", style="cyan") | |
table.add_column("Type", style="magenta") | |
table.add_column("Effectiveness", style="green") | |
for i, feather in enumerate(feathers, 1): | |
effectiveness = feather.sneeze_chance(current_turn) | |
table.add_row(str(i), feather.type, f"{effectiveness}%") | |
console.print(table) | |
def player_turn(player, feathers, current_turn, resistance): | |
console.print(f"\n[bold cyan]{player}'s turn:[/bold cyan]") | |
display_feathers(feathers, current_turn) | |
while True: | |
choice = console.input("Choose a feather (1-10): ") | |
if choice.isdigit() and 1 <= int(choice) <= 10: | |
feather = feathers[int(choice) - 1] | |
break | |
else: | |
console.print("[red]Invalid choice. Please choose a number between 1 and 10.[/red]") | |
console.print(f"Tickling with {feather.type} feather...") | |
with Progress() as progress: | |
task = progress.add_task("[green]Tickling...", total=100) | |
while not progress.finished: | |
progress.update(task, advance=random.randint(1, 10)) | |
sleep(0.1) | |
sneeze_chance = feather.sneeze_chance(current_turn) - resistance | |
if random.randint(1, 100) <= sneeze_chance: | |
console.print(Panel(f"[bold red]{player} sneezed![/bold red]")) | |
return True | |
else: | |
console.print("[green]Resisted![/green]") | |
return False | |
def play_game(player1, player2): | |
feathers = create_feathers() | |
random.shuffle(feathers) | |
current_turn = 1 | |
p1_resistance = 0 | |
p2_resistance = 0 | |
while True: | |
console.print(f"\n[bold magenta]Turn {current_turn}[/bold magenta]") | |
if player_turn(player1, feathers, current_turn, p1_resistance): | |
console.print(f"[bold green]{player2} wins![/bold green]") | |
break | |
p1_resistance += 5 | |
if player_turn(player2, feathers, current_turn, p2_resistance): | |
console.print(f"[bold green]{player1} wins![/bold green]") | |
break | |
p2_resistance += 5 | |
current_turn += 1 | |
console.print("\n[bold yellow]Game Over![/bold yellow]") | |
play_again = console.input("Play again? (y/n): ").lower() | |
if play_again == 'y': | |
play_game(player1, player2) | |
def main(): | |
console.print("[bold yellow]Welcome to the Feather Tickle Game![/bold yellow]") | |
player1 = console.input("[cyan]Enter Player 1's name: [/cyan]") | |
player2 = console.input("[cyan]Enter Player 2's name: [/cyan]") | |
play_game(player1, player2) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment