Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@Pinacolada64
Pinacolada64 / numbers.py
Created September 17, 2021 06:20
Testing comma-delimited numbers and percentages
import time
import logging
# https://docs.python.org/3/library/decimal.html?#recipes
# this does not work for me
def comma_delimited_value(value=0, right_justify=False):
"""
@Pinacolada64
Pinacolada64 / test.py
Created September 18, 2021 03:48
Learning how to access dicts int he context of an adventure game
class Player:
def __init__(self, name, player_id, stats, silver):
self.name = name
self.player_id = player_id
self.stats = {"constitution": 0, "dexterity": 0, "ego": 0, "intelligence": 0,
"strength": 0, "wisdom": 0} # creates a new stats dict for each Player
self.silver = {"in_hand": 0, "in_bank": 0, "in_bar": 0} # creates a new silver dict for each Player
# test that it works
print("Silver in hand: " + str(self.silver["in_hand"]))
@Pinacolada64
Pinacolada64 / grammatical_list.py
Created October 19, 2021 03:48
Print a list of items in a grammatically correct way
def grammatical_list(item_list):
print("Entered function")
for item in item_list:
if item[:-1] == 's':
item = "some " + item
if item.startswith(('a', 'e', 'i', 'o', 'u')):
item = "an " + item
# print(item, sep="and, ", end='')
print(item)
print("Exited function")
@Pinacolada64
Pinacolada64 / map_test.py
Created October 27, 2021 21:19
Testing map functions
from prompt_toolkit import prompt
# Test walking around on a map
"""
# * Room number (rm)
# * Location name (lo$)
# * items: monster, item, weapon, food
# * exits: north, east, south, west
# RC (room command: 1=move up,
@Pinacolada64
Pinacolada64 / list_exits.py
Created October 28, 2021 04:43
List exits from a room.
direction_names = ['North', 'East', 'South', 'West', 'Up', 'Down']
def show_exits(exits):
"""list room exits"""
exit_list = []
if exits[0]:
exit_list.append("North")
if exits[1]:
@Pinacolada64
Pinacolada64 / map_test.py
Last active November 9, 2021 23:24
Getting so close to making movement possible, I think!
# from prompt_toolkit import prompt # this doesn't work on Windows
# Test walking around on a map
"""
Data format on C64:
* Room number (rm)
* Location name (lo$)
* items: monster, item, weapon, food
* exits: north, east, south, west
@Pinacolada64
Pinacolada64 / read_map.py
Last active November 14, 2021 05:00
Reading map data from a file
class Exit(object):
def __init__(self, room_number: int, exit_list: list):
"""
Exits are contained in a list, exit_list
:param room_number: this Exit's room number
:param exit_list: list of 5 exits per room: north, east, south, west, room_connection, room_transport
"""
self.room_number = room_number
self.exits = exit_list
logging.info(f'Exit.__init__: created new exit: {room_number=} {exit_list=}')
@Pinacolada64
Pinacolada64 / text-based-rpg.py
Created November 21, 2021 01:30
Trying to fix someone's Python 2.x RPG
# A text based RPG
# from http://pythonfiddle.com/text-based-rpg-code-python/
# ryan made a few IDE-suggested tweaks:
# 'if IsDaggerEquipped == True:' -> 'if IsDaggerEquipped:'
# Import required modules
import jsonpickle # FIXME: this does not exist on python 3.x, so causes an error when used
import os
import sys
import time
@Pinacolada64
Pinacolada64 / net_server.py
Created November 24, 2021 22:25
Trying to update `net_server.py` to read json files
#!/bin/env python3
import socketserver
import json
from dataclasses import dataclass, field
import enum
import net_common as nc
@Pinacolada64
Pinacolada64 / text-adventure-demo.py
Created November 28, 2021 21:11
Modification of Al Swiegart's adventure game demo
import cmd
import textwrap
import logging
import pyreadline3 # for tab-completion and command line editing
# PyCharm had me rename worldItems -> world_items, but camelCase variables are legal in Python
# there is an option in the IDE to ignore camelCase variables, so I set that
# class design resources:
# https://codereview.stackexchange.com/questions/91069/simple-text-rpg-in-python