Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@Pinacolada64
Pinacolada64 / combat.py
Created June 27, 2025 01:27
Combat system for advanced_parser.py
# combat_system.py
import logging
from datetime import timedelta # Needed for advancing game clock
# Assuming GameClock and Player will be passed in from main.py
# We won't import them directly here to avoid circular dependencies.
# Instead, the CombatSystem will receive instances of them.
# Configure logging for this module
@Pinacolada64
Pinacolada64 / advanced_parser
Last active June 28, 2025 00:04
Advanced command parser and game states written with Gemini AI's help
import abc
import logging
from datetime import datetime, timedelta
from typing import Optional
from astral import LocationInfo, sun, moon
import pytz # python time zones
from enum import Enum
from combat import CombatSystem, Monster
@Pinacolada64
Pinacolada64 / abbreviate_statistics.py
Created June 16, 2025 21:52
Shows a data structure for abbreviating statistic names
import random
from enum import Enum, auto
# We only need one Enum to represent the stats internally.
class PlayerStat(Enum):
CHARISMA = auto()
CONSTITUTION = auto()
DEXTERITY = auto()
INTELLIGENCE = auto()
@Pinacolada64
Pinacolada64 / new_player.py
Last active June 10, 2025 05:46
Uses dict unpacking and .get()
import logging
import random
from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import Enum, auto, StrEnum
import textwrap
import doctest
class Translation(Enum):
@Pinacolada64
Pinacolada64 / text_editor.py
Last active May 24, 2025 02:32
Text editor with (maybe) better design principles
# kwargs practice
import logging
from enum import Enum, Flag
from typing import Callable, Optional
# original code:
# https://github.com/Pinacolada64/TADA/blob/e54fc3bb2ff14bae731942d24ce5addb96616216/server/text_editor.py
class DefaultLineRange(Enum):
"""
@Pinacolada64
Pinacolada64 / datetime_practice.py
Last active April 30, 2025 23:54
Practicing datetime module
from datetime import datetime
def time_delta_in_words(d1: datetime, d2: datetime):
years = abs(d1.year - d2.year)
months = abs(d1.month - d2.month)
# if d1.month - d2.month < 12 then less than an entire year between events. therefore subtract a year
if months < 12:
years -= 1
print(f"less than 12 months between deltas, years now {years=}")
days = abs(d1.day - d2.day)
@Pinacolada64
Pinacolada64 / items.py
Last active April 1, 2025 22:51
Item ID strings
from typing import Optional, Any
class Item:
def __init__(self, item_id: int, name: str, description: str, owner: Optional[None], prefix: str = "I"):
self.prefix = prefix
self.item_id = item_id
self.owner = owner # TODO: can be a Player, but moving this after Player breaks inheritance
self.name = name
self.description = description
@Pinacolada64
Pinacolada64 / fog_of_war.py
Last active March 13, 2025 07:31
Dungeon crawler with fog-of-war map reveal
import logging
import random
from typing import Optional
from enum import Enum
# Dungeon map configuration
DUNGEON_SIZE = 20
REVEAL_RADIUS = 2
dungeon = [['.' for _ in range(DUNGEON_SIZE)] for _ in range(DUNGEON_SIZE)]
@Pinacolada64
Pinacolada64 / custom_codec_registration.py
Created February 18, 2025 06:31
Register a custom codec, with example text transformation.
import codecs
# Define your custom codec
class SimpleCodec(codecs.Codec):
def encode(self, input, errors='strict'):
# For simplicity, encoding is just the reverse.
return input[::-1], len(input)
def decode(self, input, errors='strict'):
@Pinacolada64
Pinacolada64 / color_map.py
Last active February 11, 2025 06:51
A color string parser meant to handle ANSI and Commodore terminal colors
import enum
import logging
from dataclasses import dataclass
from enum import Enum
import codecs
import cbmcodecs2
from colorama import init, Fore