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
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) |
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
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 |
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 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)] |
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 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'): |
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 enum | |
import logging | |
from dataclasses import dataclass | |
from enum import Enum | |
import codecs | |
import cbmcodecs2 | |
from colorama import init, Fore |
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
from dataclasses import dataclass | |
from enum import StrEnum | |
from typing import Optional | |
# from flags import Size | |
@dataclass | |
class Item(object): |
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 logging | |
import textwrap | |
from dataclasses import asdict, dataclass, is_dataclass, field | |
from enum import Enum | |
""" | |
Goal: to display a settings menu. The way I think it should work: | |
- Enumerate through Player atributes, get a key (LINE_ENDING) | |
- Get a key name common to both SettingString.LINE_ENDING (to display in the menu item) and SettingValue.LINE_ENDING |
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 dataclasses import dataclass, field | |
from enum import Enum | |
class ClientSettingsNames(str, Enum): | |
NAME = "Name" | |
ROWS = "Screen rows" | |
COLUMNS = "Screen columns" | |
RETURN_KEY = "Return key" |
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 re | |
import logging | |
import doctest | |
import tempfile | |
def process_macros(code: list): | |
""" | |
This function processes macro definitions and stores them in a dictionary. |
NewerOlder