Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@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 / 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
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 / 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 / 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 / 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):
"""
def tada_parser(last_command=None):
logging.info("tada_parser() called")
if last_command is None:
last_command = "help"
print(f"Return: {last_command}")
command_line = input("Command: ")
if not command_line:
logging.info("Empty command line, setting to '{last_command}")
command_line = last_command
@Pinacolada64
Pinacolada64 / text-experiments.py
Created March 10, 2021 08:41
Word wrap and More prompt
import textwrap
# https://docs.python.org/3/library/textwrap.html#textwrap.TextWrapper.wrap
# https://inventwithpython.com/blog/2014/12/02/why-is-object-oriented-programming-useful-with-a-role-playing-game-example/
# https://python-prompt-toolkit.readthedocs.io/en/master/
class Terminal:
# TODO: make baud_rate and output_count be default arguments, not specified in the call for the function to work:
# TODO: outputCount should be a member of Terminal, I think:
def __init__(self, translation_type, screen_height, screen_width, more_prompt, output_count):
@Pinacolada64
Pinacolada64 / queries_original.py
Last active February 24, 2021 21:58
testing for an author which does not exist
import sqlite3
def get_cursor():
conn = sqlite3.connect("library.db")
return conn.cursor()
def select_all_records_by_author(cur, author):
sql = "SELECT * FROM books WHERE author=?"
# from "Python 101" pg. 351
import sqlite3
def get_cursor():
conn = sqlite3.connect("library.db")
return conn.cursor()
def select_all_records_by_author(cursor, author):