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 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 |
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
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]: |
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 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, |
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
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") |
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
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"])) |
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 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): | |
""" |
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
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 |
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 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): |
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 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=?" |
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 "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): |