Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@Pinacolada64
Pinacolada64 / object_subclassing.py
Last active November 27, 2023 06:36
Trying to subclass items & characters in game
from dataclasses import dataclass
import datetime
import doctest
import logging
from random import randrange
from typing import Sequence
# some of this was--sadly--cribbed from Bing AI.
# https://www.reddit.com/r/learnpython/comments/17oblv2/class_method_vs_instance_method/
@Pinacolada64
Pinacolada64 / dungeon.py
Created August 8, 2023 20:51
Random dungeon generator
# map.py
# modified from https://www.roguebasin.com/index.php?title=Python_Curses_Example_of_Dungeon-Building_Algorithm
# https://roguebasin.com/index.php/Dungeon_builder_written_in_Python/Examples
# FIXME: 2d maze generator output doesn't match examples
# TODO: get height/width of map, if > screen height/width, display quadrants or something
# TODO: display room names underneath?
# https://lvngd.com/blog/generating-and-solving-mazes-with-python/#
@Pinacolada64
Pinacolada64 / parser-classes.py
Created July 20, 2023 01:56
Make command classes for each category of command
# This is based on dot_commands.py
# some interesting ideas here:
# https://colab.research.google.com/github/interactive-fiction-class/interactive-fiction-class.github.io/blob/master/homeworks/text-adventure-game/Text_Adventure_Game.ipynb#scrollTo=8Cug7Bs3Qpdd
from dataclasses import dataclass
from typing import Callable, Any, Union
import re as regex
@dataclass
@Pinacolada64
Pinacolada64 / basic_keymap.py
Created April 29, 2023 05:58
Demonstrate a Commodore keymap with named keys.
import sys
def show_keymap():
for value, key_name in keymap.items():
print(f"{value:3} {key_name}")
if value % 20 == 0:
_ = input("Pause ('Q' quits): ")
if _.lower() == "q":
print("Aborted.")
@Pinacolada64
Pinacolada64 / text-editor.py
Last active March 15, 2023 06:31
Beginning a simple line-based text editor.
try:
import getch
except ImportError as e:
print(f"Can't import getch: {e}.")
def get_character():
"""
Wait for a character to be typed
return tuple: 'in_char': character, 'asc': ascii value
"""
@Pinacolada64
Pinacolada64 / player-x.json
Created February 9, 2023 06:52
Valid player JSON file
# file path: server/run/server/player-a.json
{
"name": "Mr. X",
"id": "x",
"connection_id": 29,
"gender": "male",
"stat": {
"chr": 10,
"con": 10,
"dex": 10,
# help for https://www.reddit.com/r/learnpython/comments/z86k01/im_trying_to_make_a_chose_your_own_adventure_game/
# game rewritten to use functions for areas, and a simple state machine:
def ask_to_play():
while True:
answer = input("would you like to play (yes/no) ")
if answer.lower().strip() == "yes":
state = "forest path"
# exit while loop
@Pinacolada64
Pinacolada64 / flag_operations.py
Last active November 29, 2022 21:01
Manipulating flags
# if '__name__' == '__main__':
import logging
flag = [
{'name': 'dungeon_master',
'status': True,
'type': 'yes/no'},
{'name': "room_descriptions",
'status': True,
@Pinacolada64
Pinacolada64 / object_classes.py
Last active November 23, 2022 23:48
Getting object classes working.
"""
A note about positional parameters:
https://www.reddit.com/r/learnpython/comments/yptsyp/comment/ivkydz0/?utm_source=share&utm_medium=web2x&context=3
"""
import random
from datetime import datetime
from dataclasses import dataclass
from typing import Tuple
@Pinacolada64
Pinacolada64 / scratch_20.py
Created November 9, 2022 07:17
Trying a different way of instantiating a character
"""
A note about positional parameters:
https://www.reddit.com/r/learnpython/comments/yptsyp/comment/ivkydz0/?utm_source=share&utm_medium=web2x&context=3
"""
from dataclasses import dataclass
from typing import Tuple